Sign in to follow this  
Vortez

fix the tabs issue?

Recommended Posts

Vortez    2714

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

Edited by Vortez

Share this post


Link to post
Share on other sites
Migi0027    4628

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

Edited by Migi0027

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this