Skip to content

Commit

Permalink
Merge pull request #228 from JordanMartinez/overrideSelectionDrop
Browse files Browse the repository at this point in the history
Add `onSelectionDrop`, which allows client to override the handling of an event where the user selects some text, drags it elsewhere, and "drops" it by releasing the mouse.
  • Loading branch information
TomasMikula committed Dec 19, 2015
2 parents a74d809 + 3a3ac26 commit 87d564b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;
import java.util.function.IntSupplier;
import java.util.function.IntUnaryOperator;
Expand All @@ -22,6 +23,7 @@
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableBooleanValue;
Expand Down Expand Up @@ -255,6 +257,18 @@ public void setUndoManager(UndoManagerFactory undoManagerFactory) {
public Duration getMouseOverTextDelay() { return mouseOverTextDelay.get(); }
public ObjectProperty<Duration> mouseOverTextDelayProperty() { return mouseOverTextDelay; }

/**
* Defines how to handle an event in which the user has selected some text, dragged it to a
* new location within the area, and released the mouse at some character {@code index}
* within the area.
*
* <p>By default, this will relocate the selected text to the character index where the mouse
* was released. To override it, use {@link #setOnSelectionDrop(IntConsumer)}.
*/
private Property<IntConsumer> onSelectionDrop = new SimpleObjectProperty<>(this::moveSelectedText);
public final void setOnSelectionDrop(IntConsumer consumer) { onSelectionDrop.setValue(consumer); }
public final IntConsumer getOnSelectionDrop() { return onSelectionDrop.getValue(); }

private final ObjectProperty<IntFunction<? extends Node>> paragraphGraphicFactory = new SimpleObjectProperty<>(null);
public void setParagraphGraphicFactory(IntFunction<? extends Node> factory) { paragraphGraphicFactory.set(factory); }
public IntFunction<? extends Node> getParagraphGraphicFactory() { return paragraphGraphicFactory.get(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ private void mouseReleased(MouseEvent e) {
case DRAG:
// move selection to the target position
CharacterHit h = area.hit(e.getX(), e.getY());
area.moveSelectedText(h.getInsertionIndex());
area.getOnSelectionDrop().accept(h.getInsertionIndex());
// do nothing, handled by mouseDragReleased
case NO_DRAG:
// do nothing, caret already repositioned in mousePressed
Expand Down

0 comments on commit 87d564b

Please sign in to comment.