/** * Find the position of a the caret at a given index * * @param index * the index * @return the location relative to this node or <code>null</code> */ public @Nullable Point2D getCareLocation(int index) { for (StyledTextNode t : this.textNodes) { if (t.getStartOffset() <= index && t.getEndOffset() >= index) { double x = t.getCharLocation(index); return sceneToLocal(t.localToScene(x, 0)); } } return null; }
private void handleSelectionChange(Observable o, TextSelection oldSelection, TextSelection newSelection) { if (newSelection.length == 0) { this.selectionMarker.setVisible(false); this.selectionMarker.resize(0, 0); } else { this.selectionMarker.setVisible(true); int start = newSelection.offset; int end = newSelection.offset + newSelection.length; this.selectionStartNode = null; this.selectionEndNode = null; for (StyledTextNode t : this.textNodes) { if (t.intersectOffset(start, end)) { if (this.selectionStartNode == null) { this.selectionStartNode = t; } this.selectionEndNode = t; } } if (this.selectionStartNode != null && this.selectionEndNode != null) { int charIndex = start - this.selectionStartNode.getStartOffset(); this.selectionStartX = this.selectionStartNode.getCharLocation(charIndex); charIndex = end - this.selectionEndNode.getStartOffset(); this.selectionEndX = this.selectionEndNode.getCharLocation(charIndex); requestLayout(); } } }
t.applyCss(); if (t.getStartOffset() <= this.caretIndex && (t.getEndOffset() > this.caretIndex || this.textNodes.get(this.textNodes.size() - 1) == t)) { double caretX = t.getCharLocation(this.caretIndex - t.getStartOffset()); double x = this.textLayoutNode.localToParent(t.getBoundsInParent().getMinX(), 0).getX() + caretX; double h = t.prefHeight(-1);