Skip to content

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

@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions