mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Add syntax highlight for node functions
This commit is contained in:
parent
7f2f1422f1
commit
2e49372957
@ -1,11 +1,16 @@
|
|||||||
package com.annimon.hotarufx.ui;
|
package com.annimon.hotarufx.ui;
|
||||||
|
|
||||||
|
import com.annimon.hotarufx.bundles.BundleLoader;
|
||||||
|
import com.annimon.hotarufx.bundles.FunctionType;
|
||||||
import com.annimon.hotarufx.lexer.HotaruLexer;
|
import com.annimon.hotarufx.lexer.HotaruLexer;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
@ -18,8 +23,13 @@ public class SyntaxHighlighter {
|
|||||||
|
|
||||||
private final CodeArea editor;
|
private final CodeArea editor;
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
|
private Set<String> nodeFunctions;
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
nodeFunctions = BundleLoader.functions().entrySet().stream()
|
||||||
|
.filter(e -> e.getValue() == FunctionType.NODE)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
editor.richChanges()
|
editor.richChanges()
|
||||||
.filter(ch -> !ch.getInserted().equals(ch.getRemoved()))
|
.filter(ch -> !ch.getInserted().equals(ch.getRemoved()))
|
||||||
.successionEnds(Duration.ofMillis(500))
|
.successionEnds(Duration.ofMillis(500))
|
||||||
@ -49,6 +59,14 @@ public class SyntaxHighlighter {
|
|||||||
spans.add(Collections.singleton(category), t.getLength());
|
spans.add(Collections.singleton(category), t.getLength());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "identifier":
|
||||||
|
if (nodeFunctions.contains(t.getText())) {
|
||||||
|
spans.add(Collections.singleton("node-function"), t.getLength());
|
||||||
|
} else {
|
||||||
|
spans.add(Collections.emptyList(), t.getLength());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
spans.add(Collections.emptyList(), t.getLength());
|
spans.add(Collections.emptyList(), t.getLength());
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user