HighDots Forums  

text selection

Javascript JavaScript language (comp.lang.javascript)


Discuss text selection in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
i.dont.need@any.more.email
 
Posts: n/a

Default text selection - 05-15-2008 , 03:46 PM






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

Reply With Quote
  #2  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: text selection - 05-15-2008 , 04:42 PM






i.dont.need (AT) any (DOT) more.email wrote:
Quote:
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

are better, for they require less type conversion (in that order).
However, the former is more generic and is therefore recommended.

Quote:
[...] 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.
This is a FAQ for which the answer can be found very quickly using your
favorite search engine. See also <http://jibbering.com/faq/#FAQ2_3>.

BTW, your message headers constitute a violation of Internet Standard 11,
and of Proposed Internet Standard RFC2822 by which it may be superseded: The
From header must contain an e-mail address (i.e., an address that refers a
mailbox of yours, which MUST receive mail), and the Message-ID header MUST
contain a message ID that consists of `<', followed by a compliant
local-part followed by `@' followed by a *Fully Qualified Domain Name*
followed by `>'.

http://tools.ietf.org/html/rfc1036
http://tools.ietf.org/html/rfc2822


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


Reply With Quote
  #3  
Old   
Jeremy
 
Posts: n/a

Default Re: text selection - 05-15-2008 , 04:48 PM



Thomas 'PointedEars' Lahn wrote:
Quote:
i.dont.need (AT) any (DOT) 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


Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: text selection - 05-15-2008 , 06:17 PM



Jeremy wrote:
Quote:
Thomas 'PointedEars' Lahn wrote:
i.dont.need (AT) any (DOT) 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,
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

Quote:
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.

Quote:
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.default.generate_news_mes sage_id", true);
user_pref("mail.identity.default.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$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
  #5  
Old   
Jeremy
 
Posts: n/a

Default Re: text selection - 05-15-2008 , 07:01 PM



Thomas 'PointedEars' Lahn wrote:
Quote:
Jeremy wrote:
Thomas 'PointedEars' Lahn wrote:
i.dont.need (AT) any (DOT) 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,

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.

Quote:
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?)

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

b) change to a standards-compliant NetNews provider
Any recommendations on this front?

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

user_pref("mail.identity.default.generate_news_mes sage_id", true);
user_pref("mail.identity.default.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


Reply With Quote
  #6  
Old   
i.dont.need@any.more.email
 
Posts: n/a

Default Re: text selection - 05-19-2008 , 08:48 PM



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


Quote:
[...] 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.


Quote:
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.


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

Shane


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.