@@ -49,7 +49,8 @@ public class JavaKeywordsDemo extends Application {
4949 private static final String BRACKET_PATTERN = "\\ [|\\ ]" ;
5050 private static final String SEMICOLON_PATTERN = "\\ ;" ;
5151 private static final String STRING_PATTERN = "\" ([^\" \\ \\ ]|\\ \\ .)*\" " ;
52- private static final String COMMENT_PATTERN = "//[^\n ]*" + "|" + "/\\ *(.|\\ R)*?\\ */" ;
52+ private static final String COMMENT_PATTERN = "//[^\n ]*" + "|" + "/\\ *(.|\\ R)*?\\ */" // for whole text processing (text blocks)
53+ + "|" + "/\\ *[^\\ v]*" + "|" + "^\\ h*\\ *([^\\ v]*|/)" ; // for visible paragraph processing (line by line)
5354
5455 private static final Pattern PATTERN = Pattern .compile (
5556 "(?<KEYWORD>" + KEYWORD_PATTERN + ")"
@@ -98,6 +99,8 @@ public void start(Stage primaryStage) {
9899 codeArea .setContextMenu ( new DefaultContextMenu () );
99100/*
100101 // recompute the syntax highlighting for all text, 500 ms after user stops editing area
102+ // Note that this shows how it can be done but is not recommended for production with
103+ // large files as it does a full scan of ALL the text every time there is a change !
101104 Subscription cleanupWhenNoLongerNeedIt = codeArea
102105
103106 // plain changes = ignore style changes that are emitted when syntax highlighting is reapplied
@@ -115,6 +118,8 @@ public void start(Stage primaryStage) {
115118 // run: `cleanupWhenNoLongerNeedIt.unsubscribe();`
116119*/
117120 // recompute syntax highlighting only for visible paragraph changes
121+ // Note that this shows how it can be done but is not recommended for production where multi-
122+ // line syntax requirements are needed, like comment blocks without a leading * on each line.
118123 codeArea .getVisibleParagraphs ().addModificationObserver
119124 (
120125 new VisibleParagraphStyler <>( codeArea , this ::computeHighlighting )
0 commit comments