Add syntax highlighting framework
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user