Skip to content

Commit 8c6e388

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents 06a2f84 + 210fd94 commit 8c6e388

File tree

29 files changed

+516
-382
lines changed

29 files changed

+516
-382
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MVN_SIGNING_KEY_PASSWORD }}
5454

5555
- name: Upload artifact
56-
uses: actions/upload-artifact@v4
56+
uses: actions/upload-artifact@v5
5757
if: ${{ !github.head_ref }}
5858
with:
5959
name: apk-debug

build-logic/convention/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
@SuppressWarnings("unused")
2525
object Versions {
2626
// Project versions
27-
private const val version = "0.24.1"
28-
const val versionCode = 90
27+
private const val version = "0.24.2"
28+
const val versionCode = 91
2929

3030
val versionName by lazy {
3131
if (CI.isCiBuild) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,13 @@ object SimpleMarkdownRenderer {
614614
val length = text.length
615615
while (index < length) {
616616
val current = text[index]
617+
if (current == '\\') {
618+
if (index + 1 < length && text[index + 1] in escapeCharacters) {
619+
nodes.add(Inline.Text(text[index + 1].toString()))
620+
index += 2
621+
continue
622+
}
623+
}
617624
if (current == '`') {
618625
val closing = text.indexOf('`', index + 1)
619626
if (closing > index) {
@@ -687,7 +694,7 @@ object SimpleMarkdownRenderer {
687694
var index = start
688695
while (index < text.length) {
689696
val c = text[index]
690-
if (c == '`' || c == '*' || c == '_' || c == '[') {
697+
if (c == '`' || c == '*' || c == '_' || c == '[' || c == '\\') {
691698
break
692699
}
693700
index++
@@ -967,6 +974,7 @@ object SimpleMarkdownRenderer {
967974
private const val leadingMargin = 24
968975
private const val indentMargin = 24
969976
private const val lineSeparator = "──────────"
977+
private val escapeCharacters = "\\`*_{}[]()#+-.!<>|:".toSet()
970978
private val DEFAULT_HEADING_SCALE = floatArrayOf(1.6f, 1.4f, 1.25f, 1.1f, 1.05f, 1.0f)
971979
}
972980

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
package io.github.rosemoe.sora.lsp.utils
2626

2727
import android.graphics.Color
28-
import android.util.Log
2928
import androidx.annotation.ColorInt
3029
import androidx.annotation.FloatRange
3130
import io.github.rosemoe.sora.lang.diagnostic.DiagnosticDetail
3231
import io.github.rosemoe.sora.lang.diagnostic.DiagnosticRegion
3332
import io.github.rosemoe.sora.lsp.editor.LspEditor
3433
import io.github.rosemoe.sora.text.CharPosition
3534
import io.github.rosemoe.sora.text.TextRange
36-
import io.github.rosemoe.sora.util.ArrayList
3735
import io.github.rosemoe.sora.widget.CodeEditor
3836
import org.eclipse.lsp4j.CompletionContext
3937
import org.eclipse.lsp4j.CompletionParams

editor/src/main/java/io/github/rosemoe/sora/data/ObjectAllocator.java

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

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

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

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

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@
2525

2626
import android.util.SparseArray;
2727

28+
import androidx.annotation.NonNull;
29+
2830
import java.util.Arrays;
2931

32+
import io.github.rosemoe.sora.text.CharArrayWrapper;
3033
import io.github.rosemoe.sora.text.FunctionCharacters;
3134

3235
public class SingleCharacterWidths {
3336

37+
/**
38+
* Floating-point precision steps.
39+
* <p>
40+
* Introduced to avoid accumulated floating-point errors.
41+
*/
42+
private final static long PRECISION = 1000L;
3443
public final float[] widths;
3544
public final SparseArray<Float> codePointWidths;
3645
public final char[] buffer;
@@ -69,7 +78,7 @@ public void clearCache() {
6978
/**
7079
* Measure a single character
7180
*/
72-
public float measureChar(char ch, Paint p) {
81+
public float measureChar(char ch, @NonNull Paint p) {
7382
var rate = 1;
7483
if (ch == '\t') {
7584
ch = ' ';
@@ -86,8 +95,9 @@ public float measureChar(char ch, Paint p) {
8695

8796
/**
8897
* Measure a single character
98+
* @param cp Code Point
8999
*/
90-
public float measureCodePoint(int cp, Paint p) {
100+
public float measureCodePoint(int cp, @NonNull Paint p) {
91101
if (cp <= 65535) {
92102
return measureChar((char) cp, p);
93103
}
@@ -103,55 +113,27 @@ public float measureCodePoint(int cp, Paint p) {
103113
/*
104114
* Measure text
105115
*/
106-
public float measureText(char[] chars, int start, int end, Paint p) {
107-
float width = 0f;
108-
for (int i = start; i < end; i++) {
109-
char ch = chars[i];
110-
if (isEmoji(ch)) {
111-
if (i + 4 <= end) {
112-
p.getTextWidths(chars, i, 4, widths);
113-
if (widths[0] > 0 && widths[1] == 0 && widths[2] == 0 && widths[3] == 0) {
114-
i += 3;
115-
width += widths[0];
116-
continue;
117-
}
118-
}
119-
int commitEnd = Math.min(end, i + 2);
120-
int len = commitEnd - i;
121-
if (len >= 0) {
122-
System.arraycopy(chars, i, buffer, 0, len);
123-
}
124-
width += p.measureText(buffer, 0, len);
125-
i += len - 1;
126-
} else if(isHandleFunctionCharacters() && FunctionCharacters.isEditorFunctionChar(ch)) {
127-
var name = FunctionCharacters.getNameForFunctionCharacter(ch);
128-
for (int j = 0;j < name.length();j++) {
129-
width += measureChar(name.charAt(j), p);
130-
}
131-
} else {
132-
width += measureChar(ch, p);
133-
}
134-
}
135-
return width;
116+
public float measureText(char[] chars, int start, int end, @NonNull Paint p) {
117+
return measureText(new CharArrayWrapper(chars, chars.length), start, end, p);
136118
}
137119

138-
public float measureText(CharSequence str, Paint p) {
120+
public float measureText(@NonNull CharSequence str, @NonNull Paint p) {
139121
return measureText(str, 0, str.length(), p);
140122
}
141123

142124
/**
143125
* Measure text
144126
*/
145-
public float measureText(CharSequence str, int start, int end, Paint p) {
146-
float width = 0f;
127+
public float measureText(@NonNull CharSequence str, int start, int end, @NonNull Paint p) {
128+
long width = 0;
147129
for (int i = start; i < end; i++) {
148130
char ch = str.charAt(i);
149131
if (isEmoji(ch)) {
150132
if (i + 4 <= end) {
151-
p.getTextWidths(str, i, i + 4, widths);
133+
p.getTextWidths(str, i, 4, widths);
152134
if (widths[0] > 0 && widths[1] == 0 && widths[2] == 0 && widths[3] == 0) {
153135
i += 3;
154-
width += widths[0];
136+
width += (long) Math.ceil(widths[0] * PRECISION);
155137
continue;
156138
}
157139
}
@@ -160,18 +142,18 @@ public float measureText(CharSequence str, int start, int end, Paint p) {
160142
for (int j = 0; j < len; j++) {
161143
buffer[j] = str.charAt(i + j);
162144
}
163-
width += p.measureText(buffer, 0, len);
145+
width += (long) Math.ceil(p.measureText(buffer, 0, len) * PRECISION);
164146
i += len - 1;
165147
} else if(isHandleFunctionCharacters() && FunctionCharacters.isEditorFunctionChar(ch)) {
166148
var name = FunctionCharacters.getNameForFunctionCharacter(ch);
167149
for (int j = 0;j < name.length();j++) {
168-
width += measureChar(name.charAt(j), p);
150+
width += (long) Math.ceil(measureChar(name.charAt(j), p) * PRECISION);
169151
}
170152
} else {
171-
width += measureChar(ch, p);
153+
width += (long) Math.ceil(measureChar(ch, p) * PRECISION);
172154
}
173155
}
174-
return width;
156+
return (float) width / PRECISION;
175157
}
176158

177159
}

0 commit comments

Comments
 (0)