CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: tab

  1. #1
    Join Date
    Mar 2004
    Posts
    235

    tab

    When using the text editor for posting since this is a coding forum and the tab key is used alot. Do some javascript that inserts a tab character and prevents a change of focus on the textarea. I'm sure like using jquery you can easily find the text area's. Even better the text areas have an id, so after the page has been loaded you can add event handlers to the textareas. Its a bit of a hack and will continue to work as you update the software (provided id's dont change, or if you just scan for all textareas regardless of ID's than it would be easier to upgrade the forum software.)

    It will make typing stuff here alot more comfortable. I dont like to open up a text editor all the time just so I can use the tab key, especially when its only a few lines of code.

    This probably has been suggested before but I never seen it happen in these (or pretty much any forums I go to).

    Thanks
    01101000011001010110110001101100011011110010000001110011011001010111100001111001

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: tab

    The TAB key is hooked by the internet browser as a toggle key. It has nothing to do with how vBulletin designed the forum code. If you want to change that, you will have to write your own web browser.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Mar 2004
    Posts
    235

    Re: tab

    I have done it before for my own purposes. All you have to do is to add an event listener using javascript for the textareas on key down/up. Have it check if the key code is a tab and if yes insert a tab character, call focus on the textarea and finally return false meaning do not do default event which is to change focus.

    A simple thing would be to just add this special code at the end of each page and have it scan for each textarea.

    Its a simple feature that will make posting code alot easier.
    01101000011001010110110001101100011011110010000001110011011001010111100001111001

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: tab

    Yes, it is possible, with some browsers..but many override it.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Mar 2004
    Posts
    235

    Re: tab

    Quote Originally Posted by PeejAvery View Post
    Yes, it is possible, with some browsers..but many override it.
    Does that mean its going to get done? Go PeejAvery you can implement it like no other . I don't mind if it works in some browsers. Like IE would be a pain to get it working it can be left out.
    01101000011001010110110001101100011011110010000001110011011001010111100001111001

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: tab

    That's for JPnyc to decide. I'm just saying that code-wise it's possible.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: tab

    a good idea with javascript. if javascript can catch user keys then I'll try to write a user script (for opera) inserting a tab character. it annoys me too that I always have to edit code it in some other editor.
    Last edited by memeloo; December 12th, 2010 at 03:27 AM.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  8. #8
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: tab

    for those who use Opera (tested in 10.60) and know how to install userscripts here's my userscript for inserting the tab charachter inside textareas (I can't figure out how to prevent tab-jump in firefox so no greasemonkey script now)

    EDIT: Code removed.

    EDIT: Code censored and re-added.
    Code:
    // ==UserScript==
    // @include http://www.codeguru.com/*
    // ==/UserScript==
    
    if (location.hostname.indexOf('www.codeguru.com') != -1)
    {
        if (location.href.match(/^http:\/\/www\.codeguru\.com\/forum/))
        {
            window.addEventListener('keypress', function (e)
            {
                var KEY_CODE_TAB = 9;
    
                if (e.which == KEY_CODE_TAB)
                {
                    if (e.target.nodeName == 'TEXTAREA')// instanceof HTMLTextAreaElement)
                    {
                        var textArea = e.target;
    
                        // get selection bunds
                        var start = textArea.selectionStart;
                        var end = textArea.selectionEnd;
    
                        // break up the text by selection
                        var text = textArea.value;
                        var pre = text.substring(0, start);
                        var sel = text.substring(start, end);
                        var post = text.substring(end);
    
                        // insert tab/spaces at the begining of the selection
                        //text = pre + "\t" + sel + post; // inserts one tab
                        text = pre + '    ' + sel + post; // inserts four spaces (like visual studio)
    
                        textArea.value = text;
    
                        // re-establish the selection, adjusted for the added characters.
                        //var insertionLength = 1; // when tab
                        var insertionLength = 4; // when spaces
                        textArea.selectionStart = start + insertionLength;
                        textArea.selectionEnd = end + insertionLength;
    
                        // cancel opera's tab behavior
                        e.cancelBubble = true;
                        e.returnValue = false;
                    }
                }
            }, false);
        }
    }
    here are the steps for installing it:
    - copy the code into a .js file
    - go to codeguru.com/forum
    - right click and choose "Edit Site Preferences"
    - change to Scripting tab
    - pickup the folder with the .js file at the bottom
    - reload the page

    EDIT: Code change.

    I've changed the code so that it inserts 4 spaces like visual studio. if you prefer tabs comment & uncomment the apropriate lines
    Last edited by memeloo; December 12th, 2010 at 03:20 AM.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  9. #9
    Join Date
    May 2002
    Posts
    10,943

    Re: tab

    You can re-add the code once you've removed the ad suppression factor.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured