text selection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • i.dont.need@any.more.email

    text selection

    Hello,

    I want to create a small bit of javascript to enable a key based
    selection within a text area. My users are in the habit of delineating
    options within anecdotal text using forward slashes, and I wanted to
    facilitate this more formally.

    I want to trap Ctrl+/ and Shift+Ctrl+/ to navigate to the next '/'
    character inside the text area or select that text respectively.
    Trapping the keystrokes was relatively easy (event.ctrlKey= =1 &&
    event.keyCode== 191), but I haven't been too successful with selections.
    I need to support IE6 and 7 as well as FireFox. How can I extend the
    selection for successive Shift+Ctrl+/ keystrokes? I have what seems to
    be a cludgy version working for FireFox, but my IE support isn't working.

    --
    Shane
  • Jeremy

    #2
    Re: text selection

    Thomas 'PointedEars' Lahn wrote:
    i.dont.need@any .more.email wrote:
    >I want to create a small bit of javascript to enable a key based
    >selection within a text area. My users are in the habit of delineating
    >options within anecdotal text using forward slashes, and I wanted to
    >facilitate this more formally.
    >>
    >I want to trap Ctrl+/ and Shift+Ctrl+/ to navigate to the next '/'
    >character inside the text area or select that text respectively.
    >Trapping the keystrokes was relatively easy (event.ctrlKey= =1 &&
    >
    event.ctrlKey
    or
    event.ctrlKey === true
    >
    <snip>
    Note that in Firefox, "/" brings up the type-to-search bar, and there is
    no way (that I could find) to disable this in Javascript
    (preventDefault , et al did nothing for me). This may have been fixed in
    recent versions, but it's something to look out for.

    Jeremy

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: text selection

      Jeremy wrote:
      Thomas 'PointedEars' Lahn wrote:
      >i.dont.need@any .more.email wrote:
      >>I want to create a small bit of javascript to enable a key based
      >>selection within a text area. My users are in the habit of
      >>delineating options within anecdotal text using forward slashes, and
      >>I wanted to facilitate this more formally.
      >>>
      >>I want to trap Ctrl+/ and Shift+Ctrl+/ to navigate to the next '/'
      >>character inside the text area or select that text respectively.
      >>Trapping the keystrokes was relatively easy (event.ctrlKey= =1 &&
      >event.ctrlKe y or event.ctrlKey === true
      ><snip>
      >
      Note that in Firefox, "/" brings up the type-to-search bar,
      When a textarea has the focus? Not here.

      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404
      Firefox/2.0.0.14
      and there is no way (that I could find) to disable this in Javascript
      (preventDefault , et al did nothing for me). This may have been fixed in
      recent versions,
      I don't remember observing the described behavior in any previous Firefox
      version, and I have been testing nightlies and on other OSes as well.
      but it's something to look out for.
      Yes, but not in a textarea.

      However, more important is that `keyCode' is not a reliable property for a
      character key. For example, `/' has keyCode == 55 here, the same as `7'
      (German 89-key compact laptop keyboard layout). `charCode' is the property
      one should be looking for, which yields the Unicode codepoint of the
      character that would be entered (here: 47); it is available with the
      proprietary `keypress' event type and perhaps the proposed `textInput' event
      type of W3C DOM Level 3 Events (WD, apparently not fully implemented yet in
      Fx 2); in any case with the standards-compliant `onkeypress' attribute.


      Your Message-ID header also appears to violate RFC2822 (and, consequently,
      RFC1036): AFAIK `.lga' is not a registered TLD (CMIIW). Since this appears
      to be caused by a flawed news server configuration, you should

      a) tell your NetNews provider to update their configuration (recommended)

      b) change to a standards-compliant NetNews provider

      c) use the following in your Thunderbird's user.js:

      user_pref("mail .identity.defau lt.generate_new s_message_id", true);
      user_pref("mail .identity.defau lt.FQDN", "your-domain.example" );

      (Replace the FQDN with a domain that you own or have permission to use.
      This is how I generate my M-IDs.)

      (This hint might also be useful for the OP and others [and is somewhat
      script-related ;-)], so I am posting it here.)


      PointedEars
      --
      Prototype.js was written by people who don't know javascript for people
      who don't know javascript. People who don't know javascript are not
      the best source of advice on designing systems that use javascript.
      -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

      Comment

      • Jeremy

        #4
        Re: text selection

        Thomas 'PointedEars' Lahn wrote:
        Jeremy wrote:
        >Thomas 'PointedEars' Lahn wrote:
        >>i.dont.need@any .more.email wrote:
        >>>I want to create a small bit of javascript to enable a key based
        >>>selection within a text area. My users are in the habit of
        >>>delineatin g options within anecdotal text using forward slashes, and
        >>>I wanted to facilitate this more formally.
        >>>>
        >>>I want to trap Ctrl+/ and Shift+Ctrl+/ to navigate to the next '/'
        >>>character inside the text area or select that text respectively.
        >>>Trapping the keystrokes was relatively easy (event.ctrlKey= =1 &&
        >>event.ctrlK ey or event.ctrlKey === true
        >><snip>
        >Note that in Firefox, "/" brings up the type-to-search bar,
        >
        When a textarea has the focus? Not here.
        Ah, I missed that in the original post. Of course, I also didn't
        consider that the ctrl key prevents this behavior in any case, so my
        concern was unwarranted. Whoops.
        >
        Your Message-ID header also appears to violate RFC2822 (and, consequently,
        RFC1036): AFAIK `.lga' is not a registered TLD (CMIIW). Since this appears
        to be caused by a flawed news server configuration, you should
        Technically, I'm not sure that's correct. The RFC does not specify that
        the domain given in the Message-ID MUST be a valid domain. Only that
        the Message-ID as a whole be globally unique ;-)

        That said, I'm dismayed but not surprised to find that my ISP is lacking
        in this area. Usenet is not a particular priority of any ISP these
        days. (Incidentally, do you always browse usenet with full headers? Or
        did you notice this because it caused some ill effect in your newsreader?)
        a) tell your NetNews provider to update their configuration (recommended)
        >
        b) change to a standards-compliant NetNews provider
        Any recommendations on this front?
        c) use the following in your Thunderbird's user.js:
        >
        user_pref("mail .identity.defau lt.generate_new s_message_id", true);
        user_pref("mail .identity.defau lt.FQDN", "your-domain.example" );
        I don't see subverting my ISP's news headers and inserting my own
        (arguably fraudulent) headers as the solution. Using a FQDN other than
        the one that generated the message id (which, unless my PC has a
        predictable FQDN [it does not] is what I would be doing) seems no more
        in line with the spirit of the RFC than what my ISP is doing.

        Jeremy

        Comment

        • i.dont.need@any.more.email

          #5
          Re: text selection

          Thomas 'PointedEars' Lahn wrote:
          >
          event.ctrlKey
          OK, the syntax seems odd, but I can get used to it.

          >[...] How can I extend the selection for successive Shift+Ctrl+/
          >keystrokes? ... but my IE support isn't working.
          >
          This is a FAQ for which the answer can be found very quickly using your
          favorite search engine.
          Unfortunately, it can't be located quickly at all, there is a plethora
          of disinformation on the subject, which to the uninitiated is difficult
          to filter. That was the point of asking here.

          See also <http://jibbering.com/faq/#FAQ2_3>.
          Utterly useless. No mention of caret positions, text ranges, bookmarks
          or any of the other information which is readily available.

          BTW, your message headers constitute a violation of Internet Standard 11,
          and of Proposed Internet Standard RFC2822
          My comment on the RFC :P

          Shane

          Comment

          Working...