6.6.4 - Alpha - 代码编辑器写入文件时考虑编码置信度
This commit is contained in:
@@ -6,7 +6,8 @@
|
|||||||
"util.dpToPx/spToPx/pxToDp/pxToSp 方法, 用于像素单位转换"
|
"util.dpToPx/spToPx/pxToDp/pxToSp 方法, 用于像素单位转换"
|
||||||
],
|
],
|
||||||
"fix": [
|
"fix": [
|
||||||
"Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_"
|
"Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_",
|
||||||
|
"代码编辑器可能使用置信度不足的编码写入文件导致内容解码异常的问题 (试修)"
|
||||||
],
|
],
|
||||||
"improvement": [
|
"improvement": [
|
||||||
"关于应用与开发者页面增加布局适配通用性并去除不必要的布局分类"
|
"关于应用与开发者页面增加布局适配通用性并去除不必要的布局分类"
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
|
|||||||
private val mDocsWebView: EWebView = binding.docs
|
private val mDocsWebView: EWebView = binding.docs
|
||||||
private val mDrawerLayout: DrawerLayout = binding.drawerLayout
|
private val mDrawerLayout: DrawerLayout = binding.drawerLayout
|
||||||
|
|
||||||
private var mCurrentCharset: Charset = StandardCharsets.UTF_8
|
private var mCurrentCharsetConfidence: Int = 0
|
||||||
|
private var mCurrentCharset: Charset = DEFAULT_CHARSET_TO_WRITE_FILE
|
||||||
private var mHadBom = false
|
private var mHadBom = false
|
||||||
private var mReadOnly = false
|
private var mReadOnly = false
|
||||||
private var mAutoCompletion: AutoCompletion? = null
|
private var mAutoCompletion: AutoCompletion? = null
|
||||||
@@ -244,7 +245,9 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
|
|||||||
val resolver = context.contentResolver
|
val resolver = context.contentResolver
|
||||||
val rawBytes = resolver.openInputStream(uri)?.use { it.readBytes() } ?: ByteArray(0)
|
val rawBytes = resolver.openInputStream(uri)?.use { it.readBytes() } ?: ByteArray(0)
|
||||||
|
|
||||||
mCurrentCharset = StringUtils.detectCharset(rawBytes).charsetOrDefault()
|
val detectedCharsetWrapper = StringUtils.detectCharset(rawBytes)
|
||||||
|
mCurrentCharsetConfidence = detectedCharsetWrapper.confidence ?: 0
|
||||||
|
mCurrentCharset = detectedCharsetWrapper.charsetOrDefault()
|
||||||
mHadBom = StringUtils.hasBom(rawBytes, mCurrentCharset)
|
mHadBom = StringUtils.hasBom(rawBytes, mCurrentCharset)
|
||||||
|
|
||||||
val effectiveBytes = if (mHadBom) {
|
val effectiveBytes = if (mHadBom) {
|
||||||
@@ -451,8 +454,21 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
|
|||||||
|
|
||||||
private fun writeTextWithCharset(uri: Uri, text: String) {
|
private fun writeTextWithCharset(uri: Uri, text: String) {
|
||||||
context.contentResolver.openOutputStream(uri, "rwt")?.use { out ->
|
context.contentResolver.openOutputStream(uri, "rwt")?.use { out ->
|
||||||
if (mHadBom) out.write(StringUtils.bomBytes(mCurrentCharset))
|
val (targetCharset, needBom) = when {
|
||||||
out.write(text.toByteArray(mCurrentCharset))
|
mHadBom -> {
|
||||||
|
mCurrentCharset to true
|
||||||
|
}
|
||||||
|
mCurrentCharsetConfidence >= MIN_CONFIDENCE_TO_WRITE_FILE -> {
|
||||||
|
mCurrentCharset to false
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
DEFAULT_CHARSET_TO_WRITE_FILE to false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needBom) {
|
||||||
|
out.write(StringUtils.bomBytes(targetCharset))
|
||||||
|
}
|
||||||
|
out.write(text.toByteArray(targetCharset))
|
||||||
} ?: throw IOException("Cannot open output stream for $uri")
|
} ?: throw IOException("Cannot open output stream for $uri")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,13 +755,19 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val TAG = EditorView::class.java.simpleName
|
private val TAG = EditorView::class.java.simpleName
|
||||||
|
|
||||||
|
private const val MIN_CONFIDENCE_TO_WRITE_FILE = 60
|
||||||
|
private val DEFAULT_CHARSET_TO_WRITE_FILE = StandardCharsets.UTF_8
|
||||||
|
|
||||||
const val EXTRA_PATH = "path"
|
const val EXTRA_PATH = "path"
|
||||||
const val EXTRA_NAME = "name"
|
const val EXTRA_NAME = "name"
|
||||||
const val EXTRA_CONTENT = "content"
|
const val EXTRA_CONTENT = "content"
|
||||||
const val EXTRA_READ_ONLY = "readOnly"
|
const val EXTRA_READ_ONLY = "readOnly"
|
||||||
const val EXTRA_SAVE_ENABLED = "saveEnabled"
|
const val EXTRA_SAVE_ENABLED = "saveEnabled"
|
||||||
const val EXTRA_RUN_ENABLED = "runEnabled"
|
const val EXTRA_RUN_ENABLED = "runEnabled"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#Thu May 29 16:36:29 CST 2025
|
#Thu May 29 19:18:00 CST 2025
|
||||||
BUILD_TIME=1748507789815
|
BUILD_TIME=1748517480683
|
||||||
COMPILE_SDK_VERSION=35
|
COMPILE_SDK_VERSION=35
|
||||||
IMAGE_QUANT_CMAKE_VERSION=3.22.1
|
IMAGE_QUANT_CMAKE_VERSION=3.22.1
|
||||||
IMAGE_QUANT_NDK_VERSION=26.1.10909125
|
IMAGE_QUANT_NDK_VERSION=26.1.10909125
|
||||||
@@ -19,6 +19,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
|
|||||||
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
||||||
TARGET_SDK_VERSION=35
|
TARGET_SDK_VERSION=35
|
||||||
TARGET_SDK_VERSION_INRT=29
|
TARGET_SDK_VERSION_INRT=29
|
||||||
VERSION_BUILD=3270
|
VERSION_BUILD=3271
|
||||||
VERSION_NAME=6.6.4 Alpha
|
VERSION_NAME=6.6.4 Alpha
|
||||||
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
||||||
|
|||||||
Reference in New Issue
Block a user