Skip to content

Commit

Permalink
Update Javadoc on overriding keyboard shortcuts.
Browse files Browse the repository at this point in the history
Resolves #339.
  • Loading branch information
TomasMikula committed Jul 18, 2016
1 parent 7cf5df1 commit a7fa36f
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -105,27 +105,23 @@
*
* <h3>Overriding keyboard shortcuts</h3>
*
* {@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:
* <pre>
* {@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<? super KeyEvent> 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()));
* }
* </pre>
*
Expand Down Expand Up @@ -627,7 +623,7 @@ public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyPa

// the rate at which to display the caret
EventStream<javafx.util.Duration> blinkRate = EventStreams.valuesOf(caretBlinkRate);

// The caret is visible in periodic intervals,
// but only when blinkCaret is true.
caretVisible = EventStreams.combine(blinkCaret, blinkRate)
Expand Down

0 comments on commit a7fa36f

Please sign in to comment.