fix(editor): migrate to editor v0.23.3

This commit is contained in:
Akash Yadav
2024-02-15 20:38:45 +05:30
parent c03fc8c32f
commit 77bfdea16d
10 changed files with 52 additions and 29 deletions
@@ -30,6 +30,7 @@ import com.itsaky.androidide.R;
import com.itsaky.androidide.databinding.LayoutSymbolItemBinding;
import com.itsaky.androidide.editor.ui.IDEEditor;
import com.itsaky.androidide.models.Symbol;
import io.github.rosemoe.sora.widget.SelectionMovement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -135,7 +136,7 @@ public class SymbolInputAdapter extends RecyclerView.Adapter<SymbolInputAdapter.
&& text.length() == 1
&& text.charAt(0) == editor.getText().charAt(cur.getLeftLine(), cur.getLeftColumn())
&& pairs.contains(text.charAt(0))) {
editor.moveSelectionRight();
editor.moveSelection(SelectionMovement.RIGHT);
} else {
editor.commitText(text);
if (selectionOffset != text.length()) {
@@ -50,6 +50,7 @@ import com.itsaky.androidide.treesitter.api.safeExecQueryCursor
import com.itsaky.androidide.utils.ILogger
import io.github.rosemoe.sora.editor.ts.spans.TsSpanFactory
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.SpanFactory
import io.github.rosemoe.sora.lang.styling.Spans
import io.github.rosemoe.sora.lang.styling.TextStyle
import io.github.rosemoe.sora.text.CharPosition
@@ -224,7 +225,7 @@ class LineSpansGenerator(
}
private fun emptySpan(column: Int): Span {
return Span.obtain(column, TextStyle.makeStyle(EditorColorScheme.TEXT_NORMAL))
return SpanFactory.obtain(column, TextStyle.makeStyle(EditorColorScheme.TEXT_NORMAL))
}
override fun adjustOnInsert(start: CharPosition, end: CharPosition) {
@@ -26,6 +26,7 @@ package io.github.rosemoe.sora.editor.ts.spans
import com.itsaky.androidide.treesitter.TSQueryCapture
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.SpanFactory
/**
* Default implementation of the [TsSpanFactory].
@@ -35,7 +36,7 @@ import io.github.rosemoe.sora.lang.styling.Span
open class DefaultSpanFactory : TsSpanFactory {
override fun createSpans(capture: TSQueryCapture, column: Int, spanStyle: Long): List<Span> {
return listOf(Span.obtain(column, spanStyle))
return listOf(SpanFactory.obtain(column, spanStyle))
}
override fun close() {
@@ -24,6 +24,7 @@ import com.itsaky.androidide.lexers.groovy.GroovyLexer
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE
import io.github.rosemoe.sora.lang.analysis.IncrementalAnalyzeManager.LineTokenizeResult
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.SpanFactory
import io.github.rosemoe.sora.lang.styling.TextStyle
/** @author Akash Yadav */
@@ -43,10 +44,11 @@ class GroovyAnalyzer : BaseIncrementalAnalyzeManager(GroovyLexer::class.java) {
when (type) {
GroovyLexer.WS -> {
if (first) {
spans.add(Span.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.TEXT_NORMAL)))
spans.add(SpanFactory.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.TEXT_NORMAL)))
first = false
}
}
GroovyLexer.ABSTRACT,
GroovyLexer.ASSERT,
GroovyLexer.BREAK,
@@ -87,7 +89,8 @@ class GroovyAnalyzer : BaseIncrementalAnalyzeManager(GroovyLexer::class.java) {
GroovyLexer.TRY,
GroovyLexer.VOID,
GroovyLexer.VOLATILE,
GroovyLexer.WHILE -> spans.add(Span.obtain(offset, SchemeAndroidIDE.forKeyword()))
GroovyLexer.WHILE -> spans.add(SpanFactory.obtain(offset, SchemeAndroidIDE.forKeyword()))
GroovyLexer.DECIMAL_LITERAL,
GroovyLexer.HEX_LITERAL,
GroovyLexer.OCT_LITERAL,
@@ -96,10 +99,14 @@ class GroovyAnalyzer : BaseIncrementalAnalyzeManager(GroovyLexer::class.java) {
GroovyLexer.HEX_FLOAT_LITERAL,
GroovyLexer.BOOL_LITERAL,
GroovyLexer.CHAR_LITERAL,
GroovyLexer.NULL_LITERAL, ->
spans.add(Span.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.LITERAL)))
GroovyLexer.NULL_LITERAL,
->
spans.add(SpanFactory.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.LITERAL)))
GroovyLexer.SINGLE_QUOTE_STRING,
GroovyLexer.STRING_LITERAL -> spans.add(Span.obtain(offset, SchemeAndroidIDE.forString()))
GroovyLexer.STRING_LITERAL -> spans.add(
SpanFactory.obtain(offset, SchemeAndroidIDE.forString()))
GroovyLexer.LPAREN,
GroovyLexer.RPAREN,
GroovyLexer.LBRACK,
@@ -145,8 +152,10 @@ class GroovyAnalyzer : BaseIncrementalAnalyzeManager(GroovyLexer::class.java) {
GroovyLexer.ELLIPSIS,
GroovyLexer.LBRACE,
GroovyLexer.RBRACE,
GroovyLexer.DOT, ->
spans.add(Span.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.OPERATOR)))
GroovyLexer.DOT,
->
spans.add(SpanFactory.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.OPERATOR)))
GroovyLexer.BOOLEAN,
GroovyLexer.BYTE,
GroovyLexer.CHAR,
@@ -155,20 +164,25 @@ class GroovyAnalyzer : BaseIncrementalAnalyzeManager(GroovyLexer::class.java) {
GroovyLexer.FLOAT,
GroovyLexer.INT,
GroovyLexer.LONG,
GroovyLexer.SHORT, ->
spans.add(Span.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.TYPE_NAME)))
GroovyLexer.COMMENT -> spans.add(Span.obtain(offset, SchemeAndroidIDE.forComment()))
GroovyLexer.SHORT,
->
spans.add(SpanFactory.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.TYPE_NAME)))
GroovyLexer.COMMENT -> spans.add(SpanFactory.obtain(offset, SchemeAndroidIDE.forComment()))
GroovyLexer.LINE_COMMENT -> handleLineCommentSpan(token, spans, offset)
GroovyLexer.AT ->
spans.add(Span.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.ANNOTATION)))
spans.add(SpanFactory.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.ANNOTATION)))
GroovyLexer.IDENTIFIER -> {
var colorId = SchemeAndroidIDE.TEXT_NORMAL
if (previous == GroovyLexer.AT) {
colorId = SchemeAndroidIDE.ANNOTATION
}
spans.add(Span.obtain(offset, TextStyle.makeStyle(colorId)))
spans.add(SpanFactory.obtain(offset, TextStyle.makeStyle(colorId)))
}
else -> spans.add(Span.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.TEXT_NORMAL)))
else -> spans.add(
SpanFactory.obtain(offset, TextStyle.makeStyle(SchemeAndroidIDE.TEXT_NORMAL)))
}
previous = type
}
@@ -27,8 +27,12 @@ import com.itsaky.androidide.utils.parseHexColor
import io.github.rosemoe.sora.editor.ts.spans.DefaultSpanFactory
import io.github.rosemoe.sora.editor.ts.spans.TsSpanFactory
import io.github.rosemoe.sora.lang.styling.Span
import io.github.rosemoe.sora.lang.styling.StaticColorSpan
import io.github.rosemoe.sora.lang.styling.SpanFactory
import io.github.rosemoe.sora.lang.styling.Styles
import io.github.rosemoe.sora.lang.styling.span.SpanColorResolver
import io.github.rosemoe.sora.lang.styling.span.SpanConstColorResolver
import io.github.rosemoe.sora.lang.styling.span.SpanExt
import io.github.rosemoe.sora.lang.styling.span.SpanExtAttrs
import io.github.rosemoe.sora.text.ContentReference
/**
@@ -110,13 +114,13 @@ class TreeSitterSpanFactory(
}
val col = column + result.range.first
val span = StaticColorSpan.obtain(
color,
textColor,
val span = SpanFactory.obtain(
col,
styleDef.makeStaticStyle()
)
span.setSpanExt(SpanExtAttrs.EXT_COLOR_RESOLVER, SpanConstColorResolver(textColor, color))
spans.add(span)
}
@@ -126,11 +130,11 @@ class TreeSitterSpanFactory(
// make sure that the default style is used for unmatched regions
if (s != 0) {
spans.add(0, Span.obtain(column, spanStyle))
spans.add(0, SpanFactory.obtain(column, spanStyle))
}
if (e != text.lastIndex) {
spans.add(Span.obtain(column + e + 1, spanStyle))
spans.add(SpanFactory.obtain(column + e + 1, spanStyle))
}
return spans
@@ -27,6 +27,7 @@ import com.itsaky.androidide.utils.KeyboardUtils
import io.github.rosemoe.sora.lang.completion.CompletionItem
import io.github.rosemoe.sora.widget.component.CompletionLayout
import io.github.rosemoe.sora.widget.component.EditorAutoCompletion
import io.github.rosemoe.sora.widget.getComponent
import java.lang.ref.WeakReference
import kotlin.math.min
@@ -146,7 +147,7 @@ class EditorCompletionWindow(val editor: IDEEditor) : EditorAutoCompletion(edito
hide()
}
editor.updateCompletionWindowPosition()
editor.getComponent(EditorAutoCompletion::class.java).updateCompletionWindowPosition()
setSize(width, min(newHeight, maxHeight.toFloat()).toInt())
if (!isShowing) {
show()
@@ -21,6 +21,7 @@ import com.itsaky.androidide.editor.api.IEditor
import com.itsaky.androidide.editor.ui.IDEEditor.Companion.log
import com.itsaky.androidide.models.Position
import com.itsaky.androidide.models.Range
import io.github.rosemoe.sora.widget.SelectionMovement
import java.io.File
/**
@@ -145,8 +146,7 @@ class EditorFeatures(
override fun goToEnd() {
withEditor {
val line = text.lineCount - 1
setSelection(line, 0)
moveSelection(SelectionMovement.TEXT_END)
}
}
@@ -71,12 +71,12 @@ class EditorSearchLayout(context: Context, val editor: IDEEditor) : FrameLayout(
return@setOnMenuItemClickListener if (it.isCheckable) {
it.isChecked = !it.isChecked
val ignoreCase = searchOptions.ignoreCase
val caseInsensitive = searchOptions.caseInsensitive
val regex = searchOptions.type == SearchOptions.TYPE_REGULAR_EXPRESSION
searchOptions =
when (it.itemId) {
0 -> SearchOptions(it.isChecked, regex)
1 -> SearchOptions(ignoreCase, it.isChecked)
1 -> SearchOptions(caseInsensitive, it.isChecked)
else -> searchOptions
}
editor.searcher.updateSearchOptions(searchOptions)
@@ -23,6 +23,7 @@ import android.graphics.RectF
import android.graphics.RenderNode
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.collection.MutableIntList
import com.itsaky.androidide.editor.BuildConfig
import io.github.rosemoe.sora.lang.styling.CodeBlock
import io.github.rosemoe.sora.lang.styling.Spans
@@ -125,7 +126,7 @@ class TracingEditorRenderer(
}
override fun drawRows(canvas: Canvas?, offset: Float, postDrawLineNumbers: LongArrayList?,
postDrawCursor: MutableList<DrawCursorTask>?, postDrawCurrentLines: LongArrayList?,
postDrawCursor: MutableList<DrawCursorTask>?, postDrawCurrentLines: MutableIntList?,
requiredFirstLn: MutableInt?) = trace("drawRows") {
super.drawRows(canvas, offset, postDrawLineNumbers, postDrawCursor, postDrawCurrentLines,
requiredFirstLn)
+1 -1
View File
@@ -6,7 +6,7 @@ junit-jupiter = "5.10.2"
kotlin = "1.9.22"
kotlin-coroutines = "1.7.3"
tree-sitter = "4.0.1"
editor = "0.22.2"
editor = "0.23.3"
glide = "4.16.0"
androidx-vectordrawable = "1.1.0"
androidx-navigation = "2.7.6"