refactor(edit): 重构编辑器自动补全功能
- 移除不必要的代码和注释 - 优化 CompletionItemConverter 中的偏移检查逻辑 - 删除编辑器右侧视图相关无用代码- 重构 RustCompletionAdapter,移除编辑背景设置功能 - 更新 edit_item_background.xml,移除未使用的样式
This commit is contained in:
parent
4179f3712c
commit
7395a39857
|
@ -87,19 +87,6 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
|
||||||
private val editStartViewModel: EditStartViewModel by lazy {
|
private val editStartViewModel: EditStartViewModel by lazy {
|
||||||
ViewModelProvider(this)[EditStartViewModel::class.java]
|
ViewModelProvider(this)[EditStartViewModel::class.java]
|
||||||
}
|
}
|
||||||
// /**
|
|
||||||
// * 编辑器右侧视图模型
|
|
||||||
// */
|
|
||||||
// private val editEndViewModel: EditEndViewModel by lazy {
|
|
||||||
// ViewModelProvider(this).get(EditEndViewModel::class.java)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 编辑器右侧视图
|
|
||||||
// */
|
|
||||||
// private val editEndBinding: EditEndBinding by lazy {
|
|
||||||
// EditEndBinding.bind(viewBinding.root)
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载主要的观察者
|
* 加载主要的观察者
|
||||||
|
@ -1076,12 +1063,10 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
rustLanguage.setCodeEditor(viewBinding.codeEditor)
|
rustLanguage.setCodeEditor(viewBinding.codeEditor)
|
||||||
|
|
||||||
val codeEditBackGroundEnable =
|
|
||||||
AppSettings.getValue(AppSettings.Setting.CodeEditBackGroundEnable, false)
|
|
||||||
val rustCompletionAdapter = RustCompletionAdapter()
|
val rustCompletionAdapter = RustCompletionAdapter()
|
||||||
rustCompletionAdapter.setEditBackground(codeEditBackGroundEnable)
|
val editorAutoCompletion = EditorAutoCompletion(viewBinding.codeEditor)
|
||||||
// viewBinding.codeEditor.setAutoCompletionItemAdapter(rustCompletionAdapter)
|
editorAutoCompletion.setAdapter(rustCompletionAdapter)
|
||||||
|
viewBinding.codeEditor.replaceComponent(EditorAutoCompletion::class.java,editorAutoCompletion)
|
||||||
viewBinding.codeEditor.isVerticalScrollBarEnabled = false
|
viewBinding.codeEditor.isVerticalScrollBarEnabled = false
|
||||||
val path = viewModel.modClass?.modFile?.absolutePath ?: ""
|
val path = viewModel.modClass?.modFile?.absolutePath ?: ""
|
||||||
CompletionItemConverter.configurationFileConversion(
|
CompletionItemConverter.configurationFileConversion(
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
package com.coldmint.rust.pro.edit
|
package com.coldmint.rust.pro.edit
|
||||||
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import android.text.style.StyleSpan
|
|
||||||
import android.view.View
|
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
|
import android.text.style.StyleSpan
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
import com.coldmint.rust.pro.R
|
import com.coldmint.rust.pro.R
|
||||||
import com.coldmint.rust.pro.databinding.EditItemBinding
|
import com.coldmint.rust.pro.databinding.EditItemBinding
|
||||||
import com.coldmint.rust.pro.tool.AppSettings
|
import com.coldmint.rust.pro.tool.AppSettings
|
||||||
import com.coldmint.rust.pro.tool.GlobalMethod
|
import com.coldmint.rust.pro.tool.GlobalMethod
|
||||||
import io.github.rosemoe.sora.widget.component.EditorCompletionAdapter
|
import io.github.rosemoe.sora.widget.component.EditorCompletionAdapter
|
||||||
import java.util.*
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,17 +38,6 @@ class RustCompletionAdapter : EditorCompletionAdapter() {
|
||||||
ForegroundColorSpan(GlobalMethod.getColorPrimary(context))
|
ForegroundColorSpan(GlobalMethod.getColorPrimary(context))
|
||||||
}
|
}
|
||||||
private val bold = StyleSpan(Typeface.BOLD)
|
private val bold = StyleSpan(Typeface.BOLD)
|
||||||
|
|
||||||
private var useEditBackground = false
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用编辑器背景
|
|
||||||
* @param enable Boolean
|
|
||||||
*/
|
|
||||||
fun setEditBackground(enable: Boolean) {
|
|
||||||
useEditBackground = enable
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getView(
|
override fun getView(
|
||||||
position: Int,
|
position: Int,
|
||||||
view: View?,
|
view: View?,
|
||||||
|
@ -58,9 +46,7 @@ class RustCompletionAdapter : EditorCompletionAdapter() {
|
||||||
): View {
|
): View {
|
||||||
|
|
||||||
val editItem = EditItemBinding.inflate(layoutInflater, parent, false)
|
val editItem = EditItemBinding.inflate(layoutInflater, parent, false)
|
||||||
if (useEditBackground) {
|
editItem.root.setBackgroundResource(R.drawable.edit_item_background)
|
||||||
editItem.root.setBackgroundResource(R.drawable.edit_item_background)
|
|
||||||
}
|
|
||||||
val completionItem = getItem(position) as RustCompletionItem
|
val completionItem = getItem(position) as RustCompletionItem
|
||||||
spannableStringBuilder.clear()
|
spannableStringBuilder.clear()
|
||||||
val label = completionItem.title
|
val label = completionItem.title
|
||||||
|
|
|
@ -208,7 +208,7 @@ object CompletionItemConverter {
|
||||||
// completionItem.extrasData = bundle
|
// completionItem.extrasData = bundle
|
||||||
// }
|
// }
|
||||||
val offset = typeInfo?.offset
|
val offset = typeInfo?.offset
|
||||||
if (offset != null && offset.isNotBlank()) {
|
if (!offset.isNullOrBlank()) {
|
||||||
//如果偏移不为空
|
//如果偏移不为空
|
||||||
val head = "@length("
|
val head = "@length("
|
||||||
val cursorOffset = if (offset.startsWith(head) && offset.endsWith(")")) {
|
val cursorOffset = if (offset.startsWith(head) && offset.endsWith(")")) {
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<solid android:color="?android:windowBackground" />
|
<solid android:color="?android:windowBackground" />
|
||||||
<!-- <corners-->
|
|
||||||
<!-- android:topLeftRadius="32dp"-->
|
|
||||||
<!-- android:topRightRadius="32dp" />-->
|
|
||||||
<!-- android:bottomLeftRadius="16dp"-->
|
|
||||||
<!-- android:bottomRightRadius="16dp"-->
|
|
||||||
|
|
||||||
<!-- <stroke-->
|
|
||||||
<!-- android:width="3dp"-->
|
|
||||||
<!-- android:color="?android:windowBackground" />-->
|
|
||||||
</shape>
|
</shape>
|
Loading…
Reference in New Issue
Block a user