Skip navigation links
org.netbeans.modules.editor.lib2/1 2.44.0 55

Package org.netbeans.spi.editor.caret

The Editor Caret SPI contains interface(s) to be implemented by clients in order to manipulate the editor carets.

See: Description

Package org.netbeans.spi.editor.caret Description

The Editor Caret SPI contains interface(s) to be implemented by clients in order to manipulate the editor carets.

Key parts of the SPI

CaretMoveHandler allows to implement a transaction that will move individual carets or change their selections.
The following code shows how all carets are moved to the end of the word they are currently on.

  
    editorCaret.moveCarets((CaretMoveContext context) -> {
        for (CaretInfo ci : context.getOriginalCarets()) {
            Position pos = target.getDocument().createPosition(Utilities.getWordEnd(target, ci.getDot()));
            context.setDot(ci, pos);
        }
    });
  
  

Navigation Filters

A boilerplate CascadingNavigationFilter is provided to make implementation of NavigationFilters easier. The boilerplate remembers the preceding filter and will delegate to it. If you create a subclass, you may call super methods moveDot and setDot to delegate to that previous filter and ultimately perform the action. Calling methods of FilterBypass will perform the caret action directly.

The filter can find out the origin of the movement or the CaretInfo for actual caret being moved. The FilterBypass implementation passed to NavigationFilter can be downcasted to NavigationFilterBypass, which provides this extended information.

Backwards compatibility

Use cases

Use cases are shown in javadoc documentation of particular methods.

Skip navigation links
org.netbeans.modules.editor.lib2/1 2.44.0 55