Forcing cursor to remain visible?

C

Christopher Finke

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
 
R

RobG

Christopher said:
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;
 
R

RobG

RobG said:
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);
 
C

Christopher Finke

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
 
R

RobG

Christopher said:
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... :)
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top