text selection

I

i.dont.need

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.
 
T

Thomas 'PointedEars' Lahn

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.
[...] 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
 
J

Jeremy

Thomas said:
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
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
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.default.generate_news_message_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
 
J

Jeremy

Thomas said:
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.default.generate_news_message_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
 
I

i.dont.need

Thomas said:
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.


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top