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

[RFE] Add smart caret positioning to org.eclipse.ui.texteditor.AbstractTextEditor #1825

Open
2 tasks done
travkin79 opened this issue Apr 17, 2024 · 1 comment
Open
2 tasks done
Labels
enhancement New feature or request

Comments

@travkin79
Copy link

travkin79 commented Apr 17, 2024

Suggestion

JDT and CDT offer a so called "smart caret positioning" in identifiers. I suggest to add that feature to org.eclipse.ui.texteditor.AbstractTextEditor so that most editors could use that feature, too. For example, the CDT LSP editor for C/C++ code (this one is based on org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor) needs the same feature and likely many other editors, too.

Smart Caret Positioning

In Java (JDT) and in C/C++ (CDT), the option "smart caret positioning" activates navigation in text editors via Ctrl + left / right to select the next / previous sub-word or to extend the current selection with Ctrl + Shift + left / right by one sub-word. By sub-word the implementation means the next word in an identifier that (potentially) uses camel case.

"Smart caret positioning" means for an identifier someInterestingIdentifier with the caret placed after some, i.e. some^InterestingIdentifier that Ctrl + right would place the caret after someInteresting, i.e. someInteresting^Identifier. Without "smart caret positioning" the caret would jump to the end of the identifier. The same applies for extending the current selection, e.g. having the selection some , i.e. ^some^InterestingIdentifier and hitting Ctrl + Shift + right extends it to someInteresting, i.e. ^someInteresting^Identifier.

Feature Request

JDT offers the following setting in the preferences (Java -> Editor):
image

I hope, we can generalize that feature so that it could be used for all editors extending the AbstractTextEditor class. Maybe the setting "smart caret positioning" could be switched off by default and could be activated by certain editors. Of course, editors could only use that feature if they have identifiers in their language.

In general, "smart caret positioning" could be extended to consider

  • camel case (e.g. someInterestingIdentifier)
  • pascal case (e.g. SomeInterestingIdentifier)
  • snake case (e.g. some_interesting_identifier)
  • kebab case (e.g. some-Interesting-identifier)

It could be useful being able to switch support for these cases on and off, depending on the use case (language) in a custom editor.

Like in JDT and CDT, it should be possible to turn "smart caret positioning" on or off using common preferences for text editor (preferences in General -> Editors -> Text Editors) or for a special text editor (in custom preference pages).

Discussion

Is there any chance to implement that feature for AbstractTextEditor? How could that be done? I guess, the AbstractTextEditor would have to know if the concrete editor's language has identifiers and would need access to the identifiers. JDT and CDT use a custom java.text.BreakIterator to implement that feature.

If adding that feature to AbstractTextEditor is not an option, I think, I would have to somehow adapt LSP4E or CDT LSP to add that feature. But that would probably result in code duplicated from JDT as it has been done for CDT.

Community

  • I understand suggesting an enhancement doesn't mandate anyone to implement it. Other contributors may consider this suggestion, or not, at their own convenience. The most efficient way to get it fixed is that I implement it myself and contribute it back as a good quality patch to the project.
@travkin79 travkin79 added the enhancement New feature or request label Apr 17, 2024
@iloveeclipse
Copy link
Member

Is there any chance to implement that feature for AbstractTextEditor?

Sure, please work on a proposal & push a PR to discuss it.

@iloveeclipse iloveeclipse changed the title Feature Request: Add smart caret positioning to org.eclipse.ui.texteditor.AbstractTextEditor [RFE] Add smart caret positioning to org.eclipse.ui.texteditor.AbstractTextEditor Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants