473,498 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forcing cursor to remain visible?

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
4 3510
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
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1538
by: GAS | last post by:
I have tried to figure this out for a couple of days now and I'm not making much headway. I have a cursor that I can't get to work properly. There are two cursors in the stored procedure. The...
2
5065
by: Pekka Jarvela | last post by:
How can I hide the cursor in C++? I am using Visual Studio .NET and the problem is that the cursor remains blinking on the opening screen on my program. How can I set it to be black so that it...
2
7849
by: Craig | last post by:
I'm trying to do this within a control I've created: Cursor.Current = Cursors.WaitCursor; During the initialization of the parent form, my control gets added to the form, and while the control...
3
1496
by: Tibor Odehnal | last post by:
Hello, i have a crazy bug on one Machine. My Application is running fine on 6 Workstations (XP an W2K) On a new one (XP) i will have a black box as cursor if i want to resize a listview...
1
3128
by: Marc Robitaille | last post by:
Hello I build a usercontrol. On this new control, I added two controls, a TextBox and a ComboBox. My ComboBox is filled with a DataTable. When the user types something in the TextBox, I apply a...
2
2234
by: (PeteCresswell) | last post by:
I've got a screen that has a subform containing an indeterminate number of records. When the user clicks "Change", I put the screen into Edit mode by unlocking all the subform's fields, setting...
5
34197
by: Paul M | last post by:
Hi All, I've been tasked with writing a z/OS C program to read and update a table (DB/2 v8). This Table contains a single row with a single column of data. This program (which will run as a...
8
18702
by: johnlichtenstein | last post by:
I am using cx_Oracle and MySQLdb to pull a lot of data from some tables and I find that the cursor.execute method uses a lot of memory that never gets garbage collected. Using fetchmany instead of...
13
3306
by: WALDO | last post by:
I have a .Net TextBox (TextBoxBase, really) in which I am appending about 20 lines of text per second. I use the AppendText() method to accomplish this. This is a great substitute for taking the...
0
7165
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
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
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...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.