Skip to content

Commit f9653dd

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents 8c6e388 + 0692e11 commit f9653dd

File tree

8 files changed

+98
-171
lines changed

8 files changed

+98
-171
lines changed

editor-lsp/src/main/java/io/github/rosemoe/sora/lsp/editor/LspEditor.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,21 @@ class LspEditor(
488488
DocumentHighlightKind.Text to EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_BACKGROUND)
489489
)
490490

491+
val borderColors = mapOf(
492+
DocumentHighlightKind.Write to EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_STRONG_BORDER),
493+
DocumentHighlightKind.Read to EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_BORDER),
494+
DocumentHighlightKind.Text to EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_BORDER)
495+
)
496+
491497
highlights.forEach {
492498
container.add(
493499
HighlightTextContainer.HighlightText(
494500
it.range.start.line,
495501
it.range.start.character,
496502
it.range.end.line,
497503
it.range.end.character,
498-
colors.getValue(it.kind ?: DocumentHighlightKind.Text)
504+
colors.getValue(it.kind ?: DocumentHighlightKind.Text),
505+
borderColors.getValue(it.kind ?: DocumentHighlightKind.Text)
499506
)
500507
)
501508
}

editor/src/main/java/io/github/rosemoe/sora/graphics/Paint.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
public class Paint extends android.graphics.Paint {
3737

3838
private float spaceWidth;
39-
private float tabWidth;
4039
private boolean renderFunctionCharacters;
4140

4241
public Paint() {
@@ -47,7 +46,6 @@ public Paint(boolean renderFunctionCharacters) {
4746
super();
4847
this.renderFunctionCharacters = renderFunctionCharacters;
4948
spaceWidth = measureText(" ");
50-
tabWidth = measureText("\t");
5149
}
5250

5351
public void setRenderFunctionCharacters(boolean renderFunctionCharacters) {
@@ -60,7 +58,6 @@ public boolean isRenderFunctionCharacters() {
6058

6159
public void onAttributeUpdate() {
6260
spaceWidth = measureText(" ");
63-
tabWidth = measureText("\t");
6461
}
6562

6663
public float getSpaceWidth() {

editor/src/main/java/io/github/rosemoe/sora/lang/styling/HighlightTextContainer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class HighlightTextContainer {
3939
var startColumn: Int,
4040
var endLine: Int,
4141
var endColumn: Int,
42-
val color: ResolvableColor = EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_BACKGROUND)
42+
val color: ResolvableColor = EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_BACKGROUND),
43+
val borderColor: ResolvableColor = EditorColor(EditorColorScheme.TEXT_HIGHLIGHT_BORDER)
4344
) {
4445
internal fun hasLength(): Boolean {
4546
return startLine < endLine || (startLine == endLine && startColumn < endColumn)

editor/src/main/java/io/github/rosemoe/sora/text/LineNumberCalculator.java

Lines changed: 0 additions & 115 deletions
This file was deleted.

editor/src/main/java/io/github/rosemoe/sora/util/BlockIntList.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,17 @@ public void separate() {
343343
this.size = divPoint;
344344
this.next = newNext;
345345
newNext.next = oldNext;
346+
347+
compute();
348+
newNext.compute();
346349
}
347350

348351
private void compute() {
349-
max = 0;
352+
int m = 0;
350353
for (int i = 0; i < size; i++) {
351-
max = Math.max(max, data[i]);
354+
m = Math.max(m, data[i]);
352355
}
356+
max = m;
353357
}
354358
}
355359

editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
import androidx.annotation.Px;
7676
import androidx.annotation.UiThread;
7777
import androidx.collection.MutableIntSet;
78-
import androidx.collection.MutableLongObjectMap;
78+
import androidx.collection.MutableLongLongMap;
7979

8080
import java.util.ArrayList;
8181
import java.util.HashMap;
@@ -116,7 +116,6 @@
116116
import io.github.rosemoe.sora.lang.styling.Span;
117117
import io.github.rosemoe.sora.lang.styling.SpanFactory;
118118
import io.github.rosemoe.sora.lang.styling.Styles;
119-
import io.github.rosemoe.sora.lang.styling.color.ResolvableColor;
120119
import io.github.rosemoe.sora.lang.styling.inlayHint.InlayHintsContainer;
121120
import io.github.rosemoe.sora.lang.styling.inlayHint.IntSetUpdateRange;
122121
import io.github.rosemoe.sora.text.CharPosition;
@@ -286,7 +285,7 @@ public class CodeEditor extends View implements ContentListener, Formatter.Forma
286285
private float dividerMarginRight;
287286
private float insertSelectionWidth;
288287
private float blockLineWidth;
289-
private float highlightedDelimiterBorderWidth;
288+
private float textBorderWidth;
290289
private float verticalScrollFactor;
291290
private float lineInfoTextSize;
292291
private float lineSpacingMultiplier = 1f;
@@ -593,7 +592,7 @@ protected void initialize(AttributeSet attrs, int defStyleAttr, int defStyleRes)
593592
dpUnit = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics()) / 10f;
594593
dividerWidth = dpUnit;
595594
insertSelectionWidth = dpUnit * 1.5f;
596-
highlightedDelimiterBorderWidth = dpUnit;
595+
textBorderWidth = dpUnit;
597596
dividerMarginLeft = dividerMarginRight = dpUnit * 2;
598597

599598
matrix = new Matrix();
@@ -1495,7 +1494,7 @@ protected void computeMatchedPositions(int line, LongArrayList positions) {
14951494
}
14961495

14971496

1498-
protected void computeHighlightPositions(int line, MutableLongObjectMap<ResolvableColor> positions) {
1497+
protected void computeHighlightPositions(int line, MutableLongLongMap positions) {
14991498
positions.clear();
15001499
if (highlightTextContainer == null) {
15011500
return;
@@ -1526,7 +1525,9 @@ protected void computeHighlightPositions(int line, MutableLongObjectMap<Resolvab
15261525
continue;
15271526
}
15281527
if (startColumn < endColumn) {
1529-
positions.put(IntPair.pack(startColumn, endColumn), highlight.getColor());
1528+
int backgroundColor = highlight.getColor().resolve(colorScheme);
1529+
int borderColor = highlight.getBorderColor().resolve(colorScheme);
1530+
positions.put(IntPair.pack(startColumn, endColumn), IntPair.pack(backgroundColor, borderColor));
15301531
}
15311532
}
15321533
}
@@ -2983,24 +2984,29 @@ public float getInsertSelectionWidth() {
29832984
}
29842985

29852986
/**
2986-
* Border width for highlight delimiter
2987+
* Border width for text border
29872988
*/
2988-
public void setHighlightedDelimiterBorderWidth(@Px float width) {
2989+
public void setTextBorderWidth(@Px float width) {
29892990
if (width < 0) {
29902991
throw new IllegalArgumentException("width can not be under zero");
29912992
}
2992-
this.highlightedDelimiterBorderWidth = width;
2993+
textBorderWidth = width;
29932994
invalidate();
29942995
}
29952996

2997+
/**
2998+
* @see #setTextBorderWidth(float)
2999+
*/
29963000
@Px
2997-
public float getHighlightedDelimiterBorderWidth() {
2998-
return highlightedDelimiterBorderWidth;
3001+
public float getTextBorderWidth() {
3002+
return textBorderWidth;
29993003
}
30003004

30013005
/**
3002-
* Get Cursor
3003-
* Internal method!
3006+
* Get text cursor.
3007+
* <p>
3008+
* Always set selection position by {@link #setSelection} or {@link #setSelectionRegion}.
3009+
* Do not modify the object returned.
30043010
*
30053011
* @return Cursor of text
30063012
*/

0 commit comments

Comments
 (0)