Add syntax highlighting framework

This commit is contained in:
2021-02-22 15:17:31 +01:00
parent f94612cf87
commit 1860d4c57f
4 changed files with 133 additions and 2 deletions

View File

@@ -1,17 +1,20 @@
package app.controllers;
import java.net.URL;
import java.util.Collection;
import java.util.ResourceBundle;
import com.google.common.eventbus.EventBus;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.TwoDimensional.Bias;
import org.fxmisc.richtext.model.TwoDimensional.Position;
import app.events.EditorChangedEvent;
import app.model.Model;
import app.service.LanguageOperations;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.input.KeyEvent;
@@ -43,6 +46,10 @@ public class EditorController implements Initializable, Controller {
this.model = model;
}
public void setHighlighting(StyleSpans<Collection<String>> highlighting) {
this.editor.setStyleSpans(0, highlighting);
}
/**
* Handles events from the editor, and reflects them in the model
* @param event The object containing metadata of the event
@@ -57,6 +64,10 @@ public class EditorController implements Initializable, Controller {
pos.getMajor() + 1,
pos.getMinor()
));
this.setHighlighting(
LanguageOperations.syntaxHighlight(
this.editor.getText(),
Model.getLanguage()));
}
}