By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Forcing cursor to remain visible?

P: n/a
I am writing a Web-based text editor that will be used mainly for
editing code. To facilitate this task, whenever the Enter button is
pressed within the textarea, the event is caught and the next line is
automatically tabbed to match the previous line. However, because I
have caught the event and manually inserted the line feed along with
the appropriate number of tabs, the textarea doesn't scroll
automatically if the line feed puts the cursor below the last line
visible on the textarea.

Is there any way to force the cursor to remain visible in this
situation?

Chris Finke

Jan 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Christopher Finke wrote:
I am writing a Web-based text editor that will be used mainly for
editing code. To facilitate this task, whenever the Enter button is
pressed within the textarea, the event is caught and the next line is
automatically tabbed to match the previous line. However, because I
have caught the event and manually inserted the line feed along with
the appropriate number of tabs, the textarea doesn't scroll
automatically if the line feed puts the cursor below the last line
visible on the textarea.

Is there any way to force the cursor to remain visible in this
situation?


Use scrollTop (non-standard, DOM 0, but widely supported), something like:

taRef.scrollTop && taRef.scrollTop += 16;

--
Rob
Jan 11 '06 #2

P: n/a
RobG wrote:
Christopher Finke wrote:
I am writing a Web-based text editor that will be used mainly for
editing code. To facilitate this task, whenever the Enter button is
pressed within the textarea, the event is caught and the next line is
automatically tabbed to match the previous line. However, because I
have caught the event and manually inserted the line feed along with
the appropriate number of tabs, the textarea doesn't scroll
automatically if the line feed puts the cursor below the last line
visible on the textarea.

Is there any way to force the cursor to remain visible in this
situation?

Use scrollTop (non-standard, DOM 0, but widely supported), something like:

taRef.scrollTop && taRef.scrollTop += 16;


Ooops, that's crap, eh? Added the 'taRef.scrollTop && ' quickly before
posting. Try:

('number' == typeof x.scrollTop) && (x.scrollTop += 16);


--
Rob
Jan 11 '06 #3

P: n/a
> Try: ('number' == typeof x.scrollTop) && (x.scrollTop += 16);

I had thought of this, but this will scroll the textarea whether or not
it would have scrolled in the first place. If I use this method, I'd
need a way to determine if the cursor is currently visible in the
textarea. Also, wouldn't the 16 only apply for a certain font size?

Chris

Jan 11 '06 #4

P: n/a
Christopher Finke wrote:
Try: ('number' == typeof x.scrollTop) && (x.scrollTop += 16);

I had thought of this, but this will scroll the textarea whether or not
it would have scrolled in the first place.


Yes.

If I use this method, I'd
need a way to determine if the cursor is currently visible in the
textarea.
Yes, as far as I know a textarea doesn't provide anything that will let
you know that. I can think of a number of ways to do it, but they all
are really hackish. If this is for code, why not copy the text into a
text editor (see below)?

Also, wouldn't the 16 only apply for a certain font size?


Yes. scrollTop is in pixels, so that's all you have. Have you
considered using some element other than a textarea? Unfortunately I
think all the alternatives are browser-specific.
Mozilla: designMode
<URL:http://developer.mozilla.org/en/docs/Rich-Text_Editing_in_Mozilla>

IE: contentEditable
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/contenteditable.asp>

mozex: edit textarea content in your choice of text editor:
<URL:http://mozex.mozdev.org/>

There's some helpful stuff here:
<URL:http://ifindkarma.typepad.com/relax/2005/01/life_in_a_texta.html>
Go nuts... :-)

--
Rob
Jan 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.