473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Jun 27 '08 #1
4 1112
Thomas 'PointedEars' Lahn wrote:
i.*********@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
Jun 27 '08 #2
Jeremy wrote:
Thomas 'PointedEars' Lahn wrote:
>i.*********@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,
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_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, <f8*******************@news.demon.co.uk>
Jun 27 '08 #3
Thomas 'PointedEars' Lahn wrote:
Jeremy wrote:
>Thomas 'PointedEars' Lahn wrote:
>>i.*********@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,

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_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
Jun 27 '08 #4
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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ed Suominen | last post by:
I'm thinking of implementing a real-time collaborative text editor in Python using Twisted. An initial plan is to use a Twisted PB server daemon that accepts user:password:file connections from...
9
by: lkrubner | last post by:
I've got a function, you can see it below, that is being called onmouseup in the textarea on my main form. The idea is to find a selection if possible and store that text in a global variable. I...
5
by: nboutelier | last post by:
Scenario: you enter "foo bar" into a text field... Is it possible through javascript to select/highlight just "foo"? formObject.select() selects all. I need to select only part of the string....
7
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in...
4
by: Adnan Siddiqi | last post by:
Hi Pardon me if I am not making any sense.What I want to know the cordinates of selected text by user so that i can save/retrieve them later.is It possible.I am lookig for both IE and Firefox...
2
by: ahynes | last post by:
HI folks, I'm a chem engineer with no VB programming knowledge (as you'll see from my question!) I want a script to open a .txt file, insert pre-defined text into the start and end of the...
2
by: ahynes | last post by:
HI folks, I need a script to open a .txt file, insert pre-defined text into the start and end of the file, then close teh saved file with a .nc extension. I'd like to have this so I can run it...
1
by: mr k | last post by:
Hi, I wanted to use mail merge with forms but Text form fields are not retained during mail merge in Word, I got the code from Microsoft but it doesn't remember the text form field options such as...
3
by: Dekortage | last post by:
Hi all... I am able to grab the text that a user has selected on a web page, using this code: function moreInfo() { if (!isIE) { var t = window.getSelection(); // act on variable "t";
1
by: wselen | last post by:
Hi everybody, Currently I am working on an function in which I want to tag certain parts of text. This is what I have now : case "djenter": var selection = str; ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.