Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Caret line position vs. paragraph position #386

Closed
ghost opened this issue Oct 23, 2016 · 5 comments
Closed

Feature request: Caret line position vs. paragraph position #386

ghost opened this issue Oct 23, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Oct 23, 2016

The methods lineStart and lineEnd move the cursor to the start and end of the paragraph, not the line. Their names should be changed to paragraphStart and paragraphEnd to avoid confusion, as well as renaming selectLine to selectParagraph.

When pressing either Home or End, the caret position should change relative to the current line, not the current paragraph, which is what users have come to expect (e.g., the text area used to write this message has typical home/end key behaviour). There are a few related issues: #384 and #360.

It would be convenient if there was a getLineNumber() method that indicated the line number within the current paragraph, such as:

StyleClassedTextArea editor = // ...
Paragraph p = editor.getCurrentParagraph();
int n = p.getLineNumber();

Or:

StyleClassedTextArea editor = // ...
int n = editor.getCurrentLineNumber(); // delegates to paragraph

Once lineStart and lineEnd provide line-level values (instead of paragraph), it implies that writing a key interceptor for cutting a line (e.g., typing Ctrl+x as per IDE behaviour) should be as simple as:

editor.lineStart(); // should clear by default
int start = editor.getCaretPosition();
editor.lineEnd(); // should clear by default
int end = textArea.getCaretPosition();
editor.deleteText( start, end );

Or, pie-in-the-sky, to avoid extraneous UI updates:

int start = editor.getCaretLineStartColumn(); 
int end = editor.getCaretLineEndColumn();
editor.deleteText( start, end );

This would also make it trivial to override the default Home/End behaviour to move the cursor to the start and end of lines, rather than paragraphs.

@JordanMartinez
Copy link
Contributor

The methods lineStart and lineEnd move the cursor to the start and end of the paragraph, not the line. Their names should be changed to paragraphStart and paragraphEnd to avoid confusion, as well as renaming selectLine to selectParagraph.

Good point.

When pressing either Home or End, the caret position should change relative to the current line, not the current paragraph, which is what users have come to expect (e.g., the text area used to write this message has typical home/end key behaviour). There are a few related issues: #384 and #360.

In other words, a paragraph that spans multiple lines is wrapped should move the caret to the start of the current line, not the paragraph itself. However, does a normal JavaFX TextArea do that?

It would be convenient if there was a getLineNumber() method that indicated the line number within the current paragraph

Such a request would probably need to expose more of TextFlows API in TextFlowExt. Also a good point.

@ghost
Copy link
Author

ghost commented Oct 24, 2016

In other words, a paragraph that spans multiple lines is wrapped should move the caret to the start of the current line, not the paragraph itself. However, does a normal JavaFX TextArea do that?

Correct; however, I'm not sure how JavaFX TextArea behaves -- I imagine that it distinguishes lines from paragraphs as that has been typical UI behaviour for editing text since 1978 or so. ;-)

@JordanMartinez
Copy link
Contributor

I imagine that it distinguishes lines from paragraphs as that has been typical UI behaviour for editing text since 1978 or so. ;-)

😄

I just tested it and you're right.

@ghost
Copy link
Author

ghost commented Oct 24, 2016

StyleClassedTextArea editor = // ...
int n = editor.getCurrentLineNumber(); // delegates to paragraph

Probably don't want delegation here. Asking the editor's line number should give the line number from the top of the text area (starting from line 1), not the current paragraph. Also, using natural numbers seems like a good fit, as opposed to whole numbers, for line numbers.

@JordanMartinez
Copy link
Contributor

This was closed by #419. See additional comments in #417.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant