Skip to content

Commit 08fb63e

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents 7c8a503 + 8c2f872 commit 08fb63e

File tree

11 files changed

+131
-38
lines changed

11 files changed

+131
-38
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
submodules: true
2828

2929
- name: Set up JDK 17
30-
uses: actions/setup-java@v4
30+
uses: actions/setup-java@v5
3131
with:
3232
java-version: 17
3333
distribution: 'temurin'

editor-lsp/gradle.properties

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
################################################################################
2+
# sora-editor - the awesome code editor for Android
3+
# https://github.com/Rosemoe/sora-editor
4+
# Copyright (C) 2020-2025 Rosemoe
5+
#
6+
# This library is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
#
11+
# This library is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public
17+
# License along with this library; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19+
# USA
20+
#
21+
# Please contact Rosemoe by email 2073412493@qq.com if you need
22+
# additional information or have any questions
23+
################################################################################
24+
POM_ARTIFACT_ID=editor-lsp
25+
POM_NAME=editor-lsp
26+
POM_DESCRIPTION=Language Server Protocol support for sora-editor
27+
POM_PACKAGING=aar

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

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.github.rosemoe.sora.lsp.editor.text
22

3-
import android.annotation.SuppressLint
43
import android.graphics.Bitmap
54
import android.graphics.BitmapFactory
65
import android.graphics.Typeface
76
import android.graphics.drawable.BitmapDrawable
87
import android.graphics.drawable.Drawable
9-
import android.os.Build
108
import android.text.SpannableStringBuilder
119
import android.text.Spanned
1210
import android.text.TextPaint
@@ -18,7 +16,6 @@ import android.text.style.RelativeSizeSpan
1816
import android.text.style.StyleSpan
1917
import android.text.style.URLSpan
2018
import android.util.Base64
21-
import androidx.annotation.RequiresApi
2219
import java.util.Locale
2320

2421
object SimpleMarkdownRenderer {
@@ -410,10 +407,11 @@ object SimpleMarkdownRenderer {
410407
val start = builder.length
411408
val drawable = globalImageProvider.load(inline.url)
412409
if (drawable != null) {
410+
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
413411
builder.append('\uFFFC') // Object replacement character
414412
val end = builder.length
415413
builder.setSpan(
416-
ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM),
414+
ImageSpan(drawable, ImageSpan.ALIGN_CENTER),
417415
start,
418416
end,
419417
SPAN_MODE
@@ -882,23 +880,36 @@ object SimpleMarkdownRenderer {
882880
*
883881
* @param maxWidth Maximum width for returned Bitmaps. Images wider than this will be scaled down preserving aspect ratio.
884882
*/
885-
class DefaultImageProvider(
883+
open class DefaultImageProvider(
886884
private val maxWidth: Int = 800
887885
): ImageProvider {
888886
override fun load(src: String): Drawable? {
889-
if (src.startsWith("data:")) {
890-
val payload = src.substringAfter("base64,")
891-
val imageByteArray = try {
892-
Base64.decode(payload, Base64.DEFAULT)
893-
} catch (_: Exception) {
894-
return null
895-
}
896-
val bitmap = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.size) ?: return null
897-
val scaledBitmap = scaleIfNeeded(bitmap, maxWidth)
898-
val drawable = BitmapDrawable(scaledBitmap)
899-
return drawable
887+
if (!src.startsWith("data:")) return null
888+
889+
val payload = src.substringAfter("base64,", "")
890+
if (payload.isEmpty()) return null
891+
892+
val imageByteArray = try {
893+
Base64.decode(payload, Base64.DEFAULT)
894+
} catch (_: Exception) {
895+
return null
900896
}
901-
return null
897+
val bitmap = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.size) ?: return null
898+
val scaledBitmap = scaleIfNeeded(bitmap, maxWidth)
899+
return BitmapDrawable(scaledBitmap)
900+
}
901+
902+
/**
903+
* Scale down a bitmap to maxWidth preserving aspect ratio. If bitmap width
904+
* is already <= maxWidth, the original bitmap is returned.
905+
*/
906+
private fun scaleIfNeeded(bmp: Bitmap, maxWidth: Int): Bitmap {
907+
val currentWidth = bmp.width
908+
if (currentWidth <= maxWidth) return bmp
909+
val ratio = maxWidth.toFloat() / currentWidth.toFloat()
910+
911+
val newHeight = (bmp.height * ratio).toInt()
912+
return Bitmap.createScaledBitmap(bmp, maxWidth, newHeight, true)
902913
}
903914
}
904915

@@ -911,20 +922,6 @@ object SimpleMarkdownRenderer {
911922
fun load(src: String): Drawable?
912923
}
913924

914-
/**
915-
* Scale down a bitmap to maxWidth preserving aspect ratio. If bitmap width
916-
* is already <= maxWidth, the original bitmap is returned.
917-
*/
918-
@SuppressLint("UseKtx")
919-
private fun scaleIfNeeded(bmp: Bitmap, maxWidth: Int): Bitmap {
920-
val currentWidth = bmp.width
921-
if (currentWidth <= maxWidth) return bmp
922-
val ratio = maxWidth.toFloat() / currentWidth.toFloat()
923-
924-
val newHeight = (bmp.height * ratio).toInt()
925-
return Bitmap.createScaledBitmap(bmp, maxWidth, newHeight, true)
926-
}
927-
928925
private sealed interface Block {
929926
class Heading(val level: Int, val inlines: List<Inline>) : Block
930927
class Paragraph(val inlines: List<Inline>) : Block

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class EditorRenderer {
115115
private final LongArrayList postDrawLineNumbers = new LongArrayList();
116116
private final MutableIntList postDrawCurrentLines = new MutableIntList();
117117
private final LongArrayList matchedPositions = new LongArrayList();
118-
private final MutableLongObjectMap<ResolvableColor> highlightPositions = new MutableLongObjectMap();
118+
private final MutableLongObjectMap<ResolvableColor> highlightPositions = new MutableLongObjectMap<>();
119119
private final SparseArray<ContentLine> preloadedLines = new SparseArray<>();
120120
private final SparseArray<Directions> preloadedDirections = new SparseArray<>();
121121
private final CodeEditor editor;

editor/src/main/java/io/github/rosemoe/sora/widget/component/EditorContextMenuCreator.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable
2828
import android.view.ContextMenu
2929
import android.view.Menu
3030
import android.view.MenuItem
31+
import io.github.rosemoe.sora.R
3132
import io.github.rosemoe.sora.event.CreateContextMenuEvent
3233
import io.github.rosemoe.sora.event.subscribeAlways
3334
import io.github.rosemoe.sora.widget.CodeEditor
@@ -48,8 +49,18 @@ open class EditorContextMenuCreator(val editor: CodeEditor) : EditorBuiltinCompo
4849
open fun onCreateContextMenu(event: CreateContextMenuEvent) {
4950
buildMenu(event.menu) {
5051

52+
item {
53+
titleRes = android.R.string.selectAll
54+
iconRes = R.drawable.round_select_all_20
55+
isEnabled = !editor.text.isEmpty()
56+
onClick {
57+
editor.selectAll()
58+
}
59+
}
60+
5161
item {
5262
titleRes = android.R.string.copy
63+
iconRes = R.drawable.round_content_copy_20
5364
isEnabled = editor.isTextSelected
5465
onClick {
5566
editor.copyText()
@@ -58,6 +69,7 @@ open class EditorContextMenuCreator(val editor: CodeEditor) : EditorBuiltinCompo
5869

5970
item {
6071
titleRes = android.R.string.cut
72+
iconRes = R.drawable.round_content_cut_20
6173
isEnabled = editor.isTextSelected
6274
onClick {
6375
editor.cutText()
@@ -66,6 +78,7 @@ open class EditorContextMenuCreator(val editor: CodeEditor) : EditorBuiltinCompo
6678

6779
item {
6880
titleRes = android.R.string.paste
81+
iconRes = R.drawable.round_content_paste_20
6982
isEnabled = editor.hasClip()
7083
onClick {
7184
editor.pasteText()
@@ -192,7 +205,7 @@ open class EditorContextMenuCreator(val editor: CodeEditor) : EditorBuiltinCompo
192205
if (iconRes != 0) {
193206
it.setIcon(iconRes)
194207
} else if (icon != null) {
195-
it.setIcon(icon)
208+
it.icon = icon
196209
}
197210
}
198211
}

language-java/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
POM_ARTIFACT_ID=language-java
2626
POM_NAME=language-java
27-
POM_DESCRIPTION=An awesome code editor library on Android
27+
POM_DESCRIPTION=Example Java language highlighter for sora-editor
2828
POM_PACKAGING=aar

language-monarch/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
POM_ARTIFACT_ID=language-monarch
2626
POM_NAME=language-monarch
27-
POM_DESCRIPTION=An awesome code editor library on Android
27+
POM_DESCRIPTION=Monarch-based language support for sora-editor
2828
POM_PACKAGING=aar

language-textmate/consumer-rules.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
-keep class org.eclipse.tm4e.languageconfiguration.internal.model.* { *; }
33
-keep class io.github.rosemoe.sora.langs.textmate.registry.model.* { *; }
44
# Fix R8 unexpectedly removed class
5-
-keep class org.joni.ast.QuantifierNode { *; }
5+
-keep class org.joni.ast.QuantifierNode { *; }
6+
# Ignore optional component
7+
-dontwarn io.github.rosemoe.oniguruma.OnigNative

language-textmate/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
POM_ARTIFACT_ID=language-textmate
2626
POM_NAME=language-textmate
27-
POM_DESCRIPTION=An awesome code editor library on Android
27+
POM_DESCRIPTION=TextMate-based language support for sora-editor
2828
POM_PACKAGING=aar
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
################################################################################
2+
# sora-editor - the awesome code editor for Android
3+
# https://github.com/Rosemoe/sora-editor
4+
# Copyright (C) 2020-2025 Rosemoe
5+
#
6+
# This library is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
#
11+
# This library is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public
17+
# License along with this library; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19+
# USA
20+
#
21+
# Please contact Rosemoe by email 2073412493@qq.com if you need
22+
# additional information or have any questions
23+
################################################################################
24+
POM_ARTIFACT_ID=language-treesitter
25+
POM_NAME=language-treesitter
26+
POM_DESCRIPTION=TreeSitter-based language support for sora-editor
27+
POM_PACKAGING=aar

0 commit comments

Comments
 (0)