Don't be mad

S

Simon

Please, don't be mad at me for posting another question here..
It's (again) about the carotposition in a textarea, i really have tried to
find a solution through the internet but i haven't succeed in finding the
right one yet.

Enough introduction, I do know exactly what i want. And that is:
I want to know when the carot(cursor) is in the first row of the
textarea(although rows do not really exist, i know) and I want to know when
the cursor is in the last row of the textarea.

Why do I want to know that?
Because when the cursor is in the first row and the keycode for "arrow-up"
event fires, the focus has to leave the textarea and go to the field above
it.
Same goes for the last row, when the arrow-down is pressed it has to go to
the next field.

And when it's in between the first and last line, nothing should happen but
goiing up and down the textarea.

Thanks,
Simon
 
J

Julian Turner

Please, don't be mad at me for posting another question here..
It's (again) about the carotposition in a textarea, i really have tried to
find a solution through the internet but i haven't succeed in finding the
right one yet.

Enough introduction, I do know exactly what i want. And that is:
I want to know when the carot(cursor) is in the first row of the
textarea(although rows do not really exist, i know) and I want to know when
the cursor is in the last row of the textarea.

Why do I want to know that?
Because when the cursor is in the first row and the keycode for "arrow-up"
event fires, the focus has to leave the textarea and go to the field above
it.
Same goes for the last row, when the arrow-down is pressed it has to go to
the next field.

And when it's in between the first and last line, nothing should happen but
goiing up and down the textarea.

Thanks,
Simon

Hi

Two possibilities occurr to me (both non-trivial).

Firstly, I assume that by "last" row, you are including the fact that
the textarea might overflow the actual visual box and so scroll, and
so you are interested in the very end of the text within the textarea.

Solution 1
----------

One solution might be to test whether the cursor "moved". I.e. if you
are at the top or bottom of the text within the text area, pressing
the up or down arrow will produce no further movement. So you could
capture its previous posiition, compare with the new, and if no
change, "assume" that you are in the first or last row.

Solution 2
----------

The alternative (assuming you are using a fixed-width font) is might
be much more messy, and might require:-

(a) Asertain if you are in the first or last line.

(b) Calculate where the "wrapping" points are in that line (i.e
where does the line wrap to the next row), by looking at the width of
the text area, the number of pixels taken up by each character of
text, for your given font size, and wrapping rules such as wrapping of
whole words.

(c) Look at whether your carot is within those points.

Probably possible, but difficult to code.

Good Luck

Julian Turner
 
J

Julian Turner

Please, don't be mad at me for posting another question here..
It's (again) about the carotposition in a textarea, i really have tried to
find a solution through the internet but i haven't succeed in finding the
right one yet.

Enough introduction, I do know exactly what i want. And that is:
I want to know when the carot(cursor) is in the first row of the
textarea(although rows do not really exist, i know) and I want to know when
the cursor is in the last row of the textarea.

Why do I want to know that?
Because when the cursor is in the first row and the keycode for "arrow-up"
event fires, the focus has to leave the textarea and go to the field above
it.
Same goes for the last row, when the arrow-down is pressed it has to go to
the next field.

And when it's in between the first and last line, nothing should happen but
goiing up and down the textarea.

Thanks,
Simon

Hi

Two possibilities occurr to me (both non-trivial).

Firstly, I assume that by "last" row, you are including the fact that
the textarea might overflow the actual visual box and so scroll, and
so you are interested in the very end of the text within the textarea.

Solution 1
----------

One solution might be to test whether the cursor "moved". I.e. if you
are at the top or bottom of the text within the text area, pressing
the up or down arrow will produce no further movement. So you could
capture its previous posiition, compare with the new, and if no
change, "assume" that you are in the first or last row.

Solution 2
----------

The alternative (assuming you are using a fixed-width font) is might
be much more messy, and might require:-

(a) Asertain if you are in the first or last line.

(b) Calculate where the "wrapping" points are in that line (i.e
where does the line wrap to the next row), by looking at the width of
the text area, the number of pixels taken up by each character of
text, for your given font size, and wrapping rules such as wrapping of
whole words.

(c) Look at whether your carot is within those points.

Probably possible, but difficult to code.

Good Luck

Julian Turner
 

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

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top