From a7fa36fc0a6af17aff820e151de8f95c8003c02b Mon Sep 17 00:00:00 2001 From: Tomas Mikula Date: Mon, 18 Jul 2016 17:09:21 -0400 Subject: [PATCH] Update Javadoc on overriding keyboard shortcuts. Resolves #339. --- .../org/fxmisc/richtext/StyledTextArea.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java index 1c48fc557..70006c8db 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java @@ -1,6 +1,6 @@ package org.fxmisc.richtext; -import static javafx.util.Duration.ZERO; +import static javafx.util.Duration.*; import static org.fxmisc.richtext.PopupAlignment.*; import static org.reactfx.EventStreams.*; import static org.reactfx.util.Tuples.*; @@ -57,10 +57,10 @@ import org.fxmisc.richtext.model.EditActions; import org.fxmisc.richtext.model.EditableStyledDocument; import org.fxmisc.richtext.model.NavigationActions; -import org.fxmisc.richtext.model.SimpleEditableStyledDocument; import org.fxmisc.richtext.model.Paragraph; import org.fxmisc.richtext.model.PlainTextChange; import org.fxmisc.richtext.model.RichTextChange; +import org.fxmisc.richtext.model.SimpleEditableStyledDocument; import org.fxmisc.richtext.model.StyleSpans; import org.fxmisc.richtext.model.StyledDocument; import org.fxmisc.richtext.model.StyledTextAreaModel; @@ -105,27 +105,23 @@ * *

Overriding keyboard shortcuts

* - * {@code StyledTextArea} comes with {@link #onKeyTypedProperty()} and - * {@link #onKeyPressedProperty()} handlers installed to handle keyboard input. - * Ordinary character input is handled by the {@code onKeyTyped} handler and - * control key combinations (including Enter and Tab) are handled by the - * {@code onKeyPressed} handler. To add or override some keyboard shortcuts, - * but keep the rest in place, you would combine the default event handler with - * a new one that adds or overrides some of the default key combinations. This - * is how to bind {@code Ctrl+S} to the {@code save()} operation: + * {@code StyledTextArea} uses {@code KEY_TYPED} handler to handle ordinary + * character input and {@code KEY_PRESSED} handler to handle control key + * combinations (including Enter and Tab). To add or override some keyboard + * shortcuts, while keeping the rest in place, you would combine the default + * event handler with a new one that adds or overrides some of the default + * key combinations. This is how to bind {@code Ctrl+S} to the {@code save()} + * operation: *
  * {@code
  * import static javafx.scene.input.KeyCode.*;
  * import static javafx.scene.input.KeyCombination.*;
  * import static org.fxmisc.wellbehaved.event.EventPattern.*;
+ * import static org.fxmisc.wellbehaved.event.InputMap.*;
  *
- * import org.fxmisc.wellbehaved.event.EventHandlerHelper;
+ * import org.fxmisc.wellbehaved.event.Nodes;
  *
- * EventHandler ctrlS = EventHandlerHelper
- *         .on(keyPressed(S, CONTROL_DOWN)).act(event -> save())
- *         .create();
- *
- * EventHandlerHelper.install(area.onKeyPressedProperty(), ctrlS);
+ * Nodes.addInputMap(area, consume(keyPressed(S, CONTROL_DOWN), event -> save()));
  * }
  * 
* @@ -627,7 +623,7 @@ public StyledTextArea(PS initialParagraphStyle, BiConsumer applyPa // the rate at which to display the caret EventStream blinkRate = EventStreams.valuesOf(caretBlinkRate); - + // The caret is visible in periodic intervals, // but only when blinkCaret is true. caretVisible = EventStreams.combine(blinkCaret, blinkRate)