Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

RichTextFX updated to versoin 0.7-M1

AuthorKarl Tauber <email>
Date2016-05-13 16:21:10 GMT+0200
Commitf10e945f692a81ac29730db6fdb96672be92dd04
Parent6ee7394
Delta27 lines added, 25 lines removed, 2-line increase
src/main/java/org/markdownwriterfx/editor/MarkdownEditorPane.java
import static javafx.scene.input.KeyCode.*;
+import static javafx.scene.input.KeyCombination.*;
import static org.fxmisc.wellbehaved.event.EventPattern.keyPressed;
+import static org.fxmisc.wellbehaved.event.InputMap.*;
import java.nio.file.Path;
import javafx.scene.Node;
import javafx.scene.control.IndexRange;
-import javafx.scene.control.ScrollBar;
-import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
+import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.undo.UndoManager;
-import org.fxmisc.wellbehaved.event.EventHandlerHelper;
+import org.fxmisc.wellbehaved.event.Nodes;
import org.markdownwriterfx.dialogs.ImageDialog;
import org.markdownwriterfx.dialogs.LinkDialog;
"(\\s*[*+-]\\s+|\\s*[0-9]+\\.\\s+|\\s+)(.*)");
+ private final VirtualizedScrollPane<StyleClassedTextArea> scrollPane;
private final StyleClassedTextArea textArea;
private final ParagraphOverlayGraphicFactory overlayGraphicFactory;
});
- EventHandlerHelper.install(textArea.onKeyPressedProperty(), EventHandlerHelper
- .on(keyPressed(ENTER)).act(this::enterPressed)
- .on(keyPressed(D, KeyCombination.SHORTCUT_DOWN)).act(this::deleteLine)
- .on(keyPressed(W, KeyCombination.ALT_DOWN)).act(this::showWhitespace)
- .create());
+ Nodes.addInputMap(textArea, sequence(
+ consume(keyPressed(ENTER), this::enterPressed),
+ consume(keyPressed(D, SHORTCUT_DOWN), this::deleteLine),
+ consume(keyPressed(W, ALT_DOWN), this::showWhitespace)
+ ));
- // search for vertical scrollbar and add change listener to update 'scrollY' property
- textArea.getChildrenUnmodifiable().addListener((InvalidationListener) e -> {
- ScrollBar vScrollBar = Utils.findVScrollBar(textArea);
- if (vScrollBar != null) {
- vScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
- double value = newValue.doubleValue();
- double maxValue = vScrollBar.maxProperty().get();
- scrollY.set((maxValue != 0) ? Math.min(Math.max(value / maxValue, 0), 1) : 0);
- });
- }
- });
+ // add listener to update 'scrollY' property
+ InvalidationListener scrollYListener = e -> {
+ double value = textArea.estimatedScrollYProperty().getValue().doubleValue();
+ double maxValue = textArea.totalHeightEstimateProperty().getOrElse(0.).doubleValue();
+ scrollY.set((maxValue != 0) ? Math.min(Math.max(value / maxValue, 0), 1) : 0);
+ };
+ textArea.estimatedScrollYProperty().addListener(scrollYListener);
+ textArea.totalHeightEstimateProperty().addListener(scrollYListener);
+
+ // create scroll pane
+ scrollPane = new VirtualizedScrollPane<StyleClassedTextArea>(textArea);
overlayGraphicFactory = new ParagraphOverlayGraphicFactory(textArea);
public Node getNode() {
- return textArea;
+ return scrollPane;
}
src/main/java/org/markdownwriterfx/editor/ParagraphOverlayGraphicFactory.java
mGetChildren.setAccessible(true);
- Class<?> textFlowExtClass = Class.forName("org.fxmisc.richtext.skin.TextFlowExt");
+ Class<?> textFlowExtClass = Class.forName("org.fxmisc.richtext.TextFlowExt");
mGetRangeShape = textFlowExtClass.getDeclaredMethod("getRangeShape", int.class, int.class);
mGetRangeShape.setAccessible(true);
src/main/java/org/markdownwriterfx/editor/WhitespaceOverlayFactory.java
import java.util.ArrayList;
import java.util.Collection;
-import javafx.collections.ObservableList;
import javafx.geometry.Rectangle2D;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.text.Text;
import org.fxmisc.richtext.Paragraph;
import org.fxmisc.richtext.StyledText;
import org.markdownwriterfx.editor.ParagraphOverlayGraphicFactory.OverlayFactory;
+import org.reactfx.collection.LiveList;
/**
@Override
public Node[] createOverlayNodes(int paragraphIndex) {
- ObservableList<Paragraph<Collection<String>>> paragraphs = getTextArea().getParagraphs();
- Paragraph<Collection<String>> par = paragraphs.get(paragraphIndex);
+ LiveList<Paragraph<Collection<String>, Collection<String>>> paragraphs = getTextArea().getParagraphs();
+ Paragraph<Collection<String>, Collection<String>> par = paragraphs.get(paragraphIndex);
ArrayList<Node> nodes = new ArrayList<>();
int segmentStart = 0;
for(StyledText<Collection<String>> segment : par.getSegments()) {
- String text = segment.toString();
+ String text = segment.getText();
int textLength = text.length();
for (int i = 0; i < textLength; i++) {