Added sample of basic syntax highlight for Kotlin
This commit is contained in:
parent
d97ac18676
commit
6011b620f9
@ -23,8 +23,8 @@ val lightTheme = ColorsScheme(
|
||||
dialogOverlay = Color(0xAA000000),
|
||||
normalScrollbar = Color(0xFFCCCCCC),
|
||||
hoverScrollbar = Color(0xFF0070D8),
|
||||
diffLineAdded = Color(0xFFd7ebd0),
|
||||
diffLineRemoved = Color(0xFFf0d4d4),
|
||||
diffLineAdded = Color(0xAAd7ebd0),
|
||||
diffLineRemoved = Color(0xAAf0d4d4),
|
||||
isLight = true,
|
||||
)
|
||||
|
||||
@ -50,8 +50,8 @@ val darkBlueTheme = ColorsScheme(
|
||||
dialogOverlay = Color(0xAA000000),
|
||||
normalScrollbar = Color(0xFF888888),
|
||||
hoverScrollbar = Color(0xFFCCCCCC),
|
||||
diffLineAdded = Color(0xFF566f5a),
|
||||
diffLineRemoved = Color(0xFF6f585e),
|
||||
diffLineAdded = Color(0xAA566f5a),
|
||||
diffLineRemoved = Color(0xAA6f585e),
|
||||
isLight = false,
|
||||
)
|
||||
|
||||
@ -76,7 +76,7 @@ val darkGrayTheme = ColorsScheme(
|
||||
dialogOverlay = Color(0xAA000000),
|
||||
normalScrollbar = Color(0xFF888888),
|
||||
hoverScrollbar = Color(0xFFCCCCCC),
|
||||
diffLineAdded = Color(0xFF5b7059),
|
||||
diffLineRemoved = Color(0xFF74595c),
|
||||
diffLineAdded = Color(0xAA5b7059),
|
||||
diffLineRemoved = Color(0xAA74595c),
|
||||
isLight = false,
|
||||
)
|
@ -1136,6 +1136,7 @@ fun SplitDiffLine(
|
||||
|
||||
@Composable
|
||||
fun DiffLineText(line: Line, diffType: DiffType, onActionTriggered: () -> Unit) {
|
||||
val fileExtension = diffType.filePath.split(".").lastOrNull()
|
||||
val text = line.text
|
||||
val hoverInteraction = remember { MutableInteractionSource() }
|
||||
val isHovered by hoverInteraction.collectIsHoveredAsState()
|
||||
@ -1170,10 +1171,7 @@ fun DiffLineText(line: Line, diffType: DiffType, onActionTriggered: () -> Unit)
|
||||
|
||||
Row {
|
||||
Text(
|
||||
text = text.replace(
|
||||
"\t",
|
||||
" "
|
||||
).removeLineDelimiters(),
|
||||
text = syntaxHighlight(fileExtension, text),
|
||||
modifier = Modifier
|
||||
.padding(start = 16.dp)
|
||||
.fillMaxSize(),
|
||||
@ -1199,6 +1197,140 @@ fun DiffLineText(line: Line, diffType: DiffType, onActionTriggered: () -> Unit)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun syntaxHighlight(fileExtension: String?, text: String): AnnotatedString {
|
||||
val cleanText = text.replace(
|
||||
"\t",
|
||||
" "
|
||||
).removeLineDelimiters()
|
||||
|
||||
return if (cleanText.trimStart().startsWith("//")) {
|
||||
AnnotatedString(cleanText, spanStyle = SpanStyle(color = Color(0xFF70C290)))
|
||||
} else {
|
||||
val words = cleanText.split(" ")
|
||||
|
||||
val builder = AnnotatedString.Builder()
|
||||
val keywords = listOf(
|
||||
"as",
|
||||
"as?",
|
||||
"break",
|
||||
"by",
|
||||
"catch",
|
||||
"class",
|
||||
"constructor",
|
||||
"continue",
|
||||
"do",
|
||||
"dynamic",
|
||||
"else",
|
||||
"false",
|
||||
"finally",
|
||||
"for",
|
||||
"fun",
|
||||
"if",
|
||||
"import",
|
||||
"in",
|
||||
"!in",
|
||||
"interface",
|
||||
"is",
|
||||
"!is",
|
||||
"null",
|
||||
"object",
|
||||
"package",
|
||||
"return",
|
||||
"super",
|
||||
"this",
|
||||
"throw",
|
||||
"true",
|
||||
"try",
|
||||
"val",
|
||||
"var",
|
||||
"when",
|
||||
"where",
|
||||
"while",
|
||||
|
||||
// Modifiers
|
||||
"actual",
|
||||
"abstract",
|
||||
"annotation",
|
||||
"companion",
|
||||
"const",
|
||||
"crossinline",
|
||||
"data",
|
||||
"enum",
|
||||
"expect",
|
||||
"external",
|
||||
"final",
|
||||
"infix",
|
||||
"inline",
|
||||
"inner",
|
||||
"internal",
|
||||
"lateinit",
|
||||
"noinline",
|
||||
"open",
|
||||
"operator",
|
||||
"out",
|
||||
"override",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"reified",
|
||||
"sealed",
|
||||
"suspend",
|
||||
"tailrec",
|
||||
"vararg",
|
||||
)
|
||||
|
||||
fun isAnnotation(word: String): Boolean = word.startsWith("@")
|
||||
|
||||
words.forEachIndexed { index, word ->
|
||||
if (keywords.contains(word)) {
|
||||
builder.append(
|
||||
AnnotatedString(
|
||||
word,
|
||||
spanStyle = SpanStyle(
|
||||
// color = Color(0xFF669ACD)
|
||||
color = Color(0xFF90c0f0)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else if (isAnnotation(word)) {
|
||||
builder.append(
|
||||
AnnotatedString(
|
||||
word,
|
||||
spanStyle = SpanStyle(
|
||||
color = Color(0xFFB3AE5F)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
builder.append(word)
|
||||
}
|
||||
|
||||
if (index < words.lastIndex) {
|
||||
builder.append(" ")
|
||||
}
|
||||
}
|
||||
|
||||
builder.toAnnotatedString()
|
||||
}
|
||||
}
|
||||
|
||||
class Testtt {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
external fun test1()
|
||||
}
|
||||
}
|
||||
//
|
||||
//class Pancakes private constructor(val pointer: Long) {
|
||||
// constructor(message: String, num: Int) : this(initialize(message, num))
|
||||
// companion object {
|
||||
// fun initialize(message: String, num: Int): Long {
|
||||
// return 0L
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@Composable
|
||||
fun LineNumber(text: String, remarked: Boolean) {
|
||||
Text(
|
||||
|
Loading…
Reference in New Issue
Block a user