Skip to content

Commit

Permalink
Expose caret origin coordinates (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
jperedadnr authored Nov 13, 2024
1 parent 12abd91 commit 5e43e95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javafx.css.PseudoClass;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.SkinBase;
Expand Down Expand Up @@ -316,12 +317,22 @@ public final void setSkinTone(EmojiSkinTone value) {
}

/**
* The current position of the caret within the text.
* The current position of the caret within the text, in terms of characters.
*/
final ReadOnlyIntegerWrapper caretPosition = new ReadOnlyIntegerWrapper(this, "caretPosition", 0);
public final int getCaretPosition() { return caretPosition.get(); }
public final ReadOnlyIntegerProperty caretPositionProperty() { return caretPosition.getReadOnlyProperty(); }

/**
* The current location of the caret node, in RTA local coordinates.
*/
final ReadOnlyObjectWrapper<Point2D> caretOriginProperty = new ReadOnlyObjectWrapper<>(this, "caretOrigin", new Point2D(-1, -1));
public final ReadOnlyObjectProperty<Point2D> caretOriginProperty() {
return caretOriginProperty.getReadOnlyProperty();
}
public final Point2D getCaretOrigin() {
return caretOriginProperty.get();
}

/**
* The current decoration at the caret.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ protected void invalidated() {
getSkinnable().decorationAtCaret.bind(viewModel.decorationAtCaretProperty());
getSkinnable().decorationAtParagraph.bind(viewModel.decorationAtParagraphProperty());
caretPositionProperty.bind(viewModel.caretPositionProperty());
getSkinnable().caretOriginProperty.bind(caretOriginProperty);
promptNode.visibleProperty().bind(promptVisibleBinding);
promptNode.fontProperty().bind(promptFontBinding);
} else {
Expand All @@ -402,6 +403,7 @@ protected void invalidated() {
getSkinnable().decorationAtCaret.unbind();
getSkinnable().decorationAtParagraph.unbind();
caretPositionProperty.unbind();
getSkinnable().caretOriginProperty.unbind();
promptNode.visibleProperty().unbind();
promptNode.fontProperty().unbind();
}
Expand Down

0 comments on commit 5e43e95

Please sign in to comment.