fix the tabs issue?

Started by
0 comments, last by Migi0027 9 years, 11 months ago

Something that annoy me when posting code is, when you press tab, instead of making a tab, you loose the keyboard/mouse focus instead.

Could this be fixed? And if you fix it, should as well do like vs and make it work on multiples selected lines as well, i find this feature incredibly usefull in visual studio.

But i would set up for a regular tab if that's fesable.

Just saying smile.png

Advertisement

I have the same issue, it would be awesome if we could get that implemented.

if you're interested, I made a small demo that shows how it 'could' be done, my javascript skills aren't top, just saying. happy.png

http://jsfiddle.net/e5PK5/11/

But if you're too lazy to click the link, here's the code:


HTML::>
<textarea style="width:100%;" rows="25" id="Content">
........
</textarea>

JS::>
/*********************************/
// Fellow Game-Devs, here ya go! //
/*********************************/

$(document).ready(function () {
    // Remember, is shift down?
    var bShiftDown = false;

    $(document).delegate('#Content', 'keyup', function (e) {
        // Shift Up
        if ((e.keyCode || e.which) == 16) bShiftDown = false;
    });

    $(document).delegate('#Content', 'keydown', function (e) {
        // Store it
        var keyCode = e.keyCode || e.which;

        // Shift Down
        if (keyCode == 16) bShiftDown = true;

        // Tab Down
        if (keyCode == 9) {
            e.preventDefault();

            // Get the positions
            var start = $(this).get(0).selectionStart;
            var end = $(this).get(0).selectionEnd;

            // What type of command is this? Indent, or Dedent? ( If that's even a word )
            if (!bShiftDown) {
                // Get array of lines and add \t
                var code = $(this).val().substring(start, end).match(/[^\r\n]+/g);
                if (!code) return;
                for (var i = 0; i < code.length; i++) {
                    code[i] = '\t' + code[i];
                }

                // Fill it in
                $(this).val($(this).val().substring(0, start) + code.join('\n') + $(this).val().substring(end));

                // Remember to put the cursor somewhere!
                $(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1;
            } else {
                // Get array of lines and remove one \t
                // SUGGESTION: maybe remove some spaces if no t found...
                var code = $(this).val().substring(start, end).match(/[^\r\n]+/g);
                if (!code) return;
                for (var i = 0; i < code.length; i++) {
                    code[i] = code[i].replace("\t", '');
                }

                // Fill it in
                $(this).val($(this).val().substring(0, start) + code.join('\n') + $(this).val().substring(end));

                // Remember to put the cursor there!
                $(this).get(0).selectionStart = $(this).get(0).selectionEnd = start;
            }
        }
    });
});


And you reached the bottom!

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement