Skip to content

Commit

Permalink
In highlighting demos, re-highlight even if only the style changed (n…
Browse files Browse the repository at this point in the history
…ot the text).

Fixes #135.
  • Loading branch information
TomasMikula committed Sep 9, 2015
1 parent 1639f50 commit 9ee3643
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void start(Stage primaryStage) {
CodeArea codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));

codeArea.textProperty().addListener((obs, oldText, newText) -> {
codeArea.setStyleSpans(0, computeHighlighting(newText));
codeArea.richChanges().subscribe(change -> {
codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
});
codeArea.replaceText(0, 0, sampleCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.PlainTextChange;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder;
import org.reactfx.EventStream;
Expand Down Expand Up @@ -91,11 +90,11 @@ public void start(Stage primaryStage) {
executor = Executors.newSingleThreadExecutor();
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
EventStream<PlainTextChange> textChanges = codeArea.plainTextChanges();
textChanges
EventStream<?> richChanges = codeArea.richChanges();
richChanges
.successionEnds(Duration.ofMillis(500))
.supplyTask(this::computeHighlightingAsync)
.awaitLatest(textChanges)
.awaitLatest(richChanges)
.map(Try::get)
.subscribe(this::applyHighlighting);
codeArea.replaceText(0, 0, sampleCode);
Expand Down

0 comments on commit 9ee3643

Please sign in to comment.