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

Open up access to CharacterHit for subclasses of StyledTextArea #221

Merged
merged 4 commits into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.OptionalInt;

class CharacterHit {
public class CharacterHit {

public static CharacterHit insertionAt(int insertionIndex) {
return new CharacterHit(OptionalInt.empty(), insertionIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.reactfx.value.Val;
import org.reactfx.value.Var;

public class ParagraphBox<S, PS> extends Region {
class ParagraphBox<S, PS> extends Region {

/**
* An opaque class representing horizontal caret offset.
Expand Down Expand Up @@ -69,7 +69,7 @@ public ObjectProperty<IntFunction<? extends Node>> graphicFactoryProperty() {
public void setIndex(int index) { this.index.setValue(index); }
public int getIndex() { return index.getValue(); }

public ParagraphBox(Paragraph<S, PS> par, BiConsumer<? super TextExt, S> applyStyle, BiConsumer<TextFlow, PS> applyParagraphStyle) {
ParagraphBox(Paragraph<S, PS> par, BiConsumer<? super TextExt, S> applyStyle, BiConsumer<TextFlow, PS> applyParagraphStyle) {
this.getStyleClass().add("paragraph-box");
this.text = new ParagraphText<>(par, applyStyle);
applyParagraphStyle.accept(this.text, par.getParagraphStyle());
Expand Down
18 changes: 17 additions & 1 deletion richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,23 @@ CharacterHit hit(ParagraphBox.CaretOffsetX x, double y) {
}
}

CharacterHit hit(double x, double y) {
/**
* Helpful for determining which letter is at point x, y:
* <pre>
* {@code
* StyledTextArea area = // creation code
* area.addEventHandler(MouseEvent.MOUSE_PRESSED, (MouseEvent e) -> {
* CharacterHit hit = area.hit(e.getX(), e.getY());
* int characterPosition = hit.getInsertionIndex();
*
* // move the caret to that character's position
* area.moveTo(characterPosition, SelectionPolicy.CLEAR);
* }}
* </pre>
* @param x
* @param y
*/
public CharacterHit hit(double x, double y) {
VirtualFlowHit<Cell<Paragraph<S, PS>, ParagraphBox<S, PS>>> hit = virtualFlow.hit(x, y);
if(hit.isBeforeCells()) {
return CharacterHit.insertionAt(0);
Expand Down