[Editor] Improve XML and Java syntax highlighting

This commit is contained in:
2021-03-15 23:38:08 +01:00
parent 9932d0fd85
commit 9fcdfdaf92
3 changed files with 27 additions and 14 deletions

View File

@@ -25,7 +25,7 @@ class XmlSyntaxHighlighter : SyntaxHighlighter {
matcher.groups["ELEMENT"] != null -> {
add(listOf("tagmark"), matcher.end("OPEN") - matcher.start("OPEN"))
add(listOf("namespace"), matcher.end("NS") - matcher.end("OPEN"))
add(listOf("anytag"), matcher.end("ELEM") - matcher.end("NS"))
add(listOf("tagname"), matcher.end("ELEM") - matcher.end("NS"))
val attributesString = matcher.groups["ATTRS"]?.let(MatchGroup::value)?.takeIf(String::isNotEmpty)
val attributesStringLength = attributesString?.length ?: 0
@@ -36,7 +36,7 @@ class XmlSyntaxHighlighter : SyntaxHighlighter {
add(emptyList(), attr.range.first - last)
add(listOf("attribute"), attr.end("ATTR") - attr.start("ATTR"))
add(listOf("tagmark"), attr.end("EQ") - attr.end("ATTR"))
add(listOf("avalue"), attr.end("VALUE") - attr.end("EQ"))
add(listOf("value"), attr.end("VALUE") - attr.end("EQ"))
last = attr.end
}

View File

@@ -1,5 +1,6 @@
package com.bartlomiejpluta.base.editor.code.stylesheet
import javafx.scene.text.FontPosture
import javafx.scene.text.FontWeight
import tornadofx.*
@@ -68,6 +69,7 @@ class JavaSyntaxHighlightingStylesheet : Stylesheet() {
comment {
fill = c("#808080")
fontStyle = FontPosture.ITALIC
}
paragraphBox and hasCaret {

View File

@@ -3,9 +3,7 @@ package com.bartlomiejpluta.base.editor.code.stylesheet
import javafx.scene.paint.Color
import javafx.scene.text.FontPosture
import javafx.scene.text.FontWeight
import tornadofx.Stylesheet
import tornadofx.c
import tornadofx.cssclass
import tornadofx.*
class XmlSyntaxHighlightingStylesheet : Stylesheet() {
@@ -13,11 +11,17 @@ class XmlSyntaxHighlightingStylesheet : Stylesheet() {
val prolog by cssclass()
val namespace by cssclass()
val tagmark by cssclass()
val anytag by cssclass()
val tagname by cssclass()
val paren by cssclass()
val attribute by cssclass()
val avalue by cssclass()
val value by cssclass()
val comment by cssclass()
val paragraphBox by cssclass()
val paragraphText by cssclass()
val hasCaret by csspseudoclass()
val tabSize by cssproperty<Int>("-fx-tab-size")
}
init {
@@ -27,15 +31,16 @@ class XmlSyntaxHighlightingStylesheet : Stylesheet() {
}
namespace {
fill = Color.DARKRED
fill = Color.DARKVIOLET
}
tagmark {
fill = Color.GRAY
}
anytag {
fill = Color.CRIMSON
tagname {
fill = c("#000080")
fontWeight = FontWeight.BOLD
}
paren {
@@ -44,15 +49,21 @@ class XmlSyntaxHighlightingStylesheet : Stylesheet() {
}
attribute {
fill = Color.DARKVIOLET
fill = Color.DARKSLATEBLUE
fontStyle = FontPosture.ITALIC
}
avalue {
fill = Color.BLACK
value {
fill = c("#008000")
}
comment {
fill = Color.TEAL
fill = c("#808080")
fontStyle = FontPosture.ITALIC
}
paragraphText {
tabSize.value = 3
}
}
}