Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/CodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import me.yricky.oh.abcd.cfm.FieldType
import me.yricky.oh.abcd.cfm.MethodTag
import me.yricky.oh.abcd.code.Code
import me.yricky.oh.abcd.code.TryBlock
import me.yricky.oh.abcd.decompiler.ToJs
import me.yricky.oh.abcd.isa.*
import me.yricky.oh.abcd.isa.util.BaseInstParser
import me.yricky.oh.abcd.isa.util.BaseInstParser.ANNO_ASM_NAME
Expand Down Expand Up @@ -329,6 +330,71 @@ class CodeView(val code: Code,override val hap:HapSession):AttachHapPage() {
}

}
}, composeSelectContent { _: Boolean ->
Image(Icons.javaScript(), null, Modifier.fillMaxSize())
} to composeContent {
Box(
Modifier.fillMaxSize().padding(end = 8.dp, bottom = 8.dp, top = 8.dp)
.clip(RoundedCornerShape(8.dp))
.border(2.dp, MaterialTheme.colorScheme.primaryContainer, RoundedCornerShape(8.dp))
.padding(8.dp)
) {
MultiNodeSelectionContainer {
val range = multiNodeSelectionState.rememberSelectionChange()
val dcmpTexts = remember {
listOf(kotlin.runCatching { ToJs(code.asm).toJS() }.getOrElse { "${it.message}\n${it.stackTraceToString()}" })
}
//处理文本选择等操作
LaunchedEffect(null){
textActionFlow.collectLatest { when(it){
is TextAction.Copy -> {
clipboardManager.setText(buildAnnotatedString {
dcmpTexts.forEachIndexed { index, asmStr ->
it.range.rangeOf(index,asmStr)?.let { r ->
append(asmStr.subSequence(r.start,r.endExclusive))
append('\n')
}
}
})
}
is TextAction.SelectAll -> {
multiNodeSelectionState.selectedFrom = MultiNodeSelectionState.SelectionBound.Zero
multiNodeSelectionState.selectedTo = MultiNodeSelectionState.SelectionBound.from(dcmpTexts.size,dcmpTexts.lastOrNull()?.length ?: 0)
}
else -> { }
} }
}
LazyColumnWithScrollBar {
itemsIndexed(dcmpTexts) { index, str ->
Row {
val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }
val selectColor = LocalTextSelectionColors.current.backgroundColor
val thisRange = range?.rangeOf(index, str)
Column(Modifier.fillMaxSize()) {
Text(
text = remember(thisRange) {
val sp = mutableListOf<AnnotatedString.Range<SpanStyle>>()
if(thisRange != null){
sp.add(AnnotatedString.Range(
SpanStyle(background = selectColor),
thisRange.start,
thisRange.endExclusive,
))
}
AnnotatedString(str, sp, emptyList(),)
},
style = codeStyle,
modifier = Modifier
.withMultiNodeSelection({ layoutResult.value }, index)
.fillMaxWidth(),
onTextLayout = { layoutResult.value = it },
)
}
}
}
}
}
}
}, composeSelectContent { _: Boolean ->
Image(Icons.listFiles(), null, Modifier.fillMaxSize().alpha(0.5f), colorFilter = grayColorFilter)
} to composeContent {
Expand Down
7 changes: 7 additions & 0 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ object Icons{
} else {
painterResource("ic/greyKey/greyKey.svg")
}

@Composable
fun javaScript() = if (isDarkTheme()) {
painterResource("ic/javaScript/javaScript_dark.svg")
} else {
painterResource("ic/javaScript/javaScript.svg")
}
}

@Composable
Expand Down
16 changes: 0 additions & 16 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,4 @@ fun MethodItem.defineStr(showClass:Boolean = false):String = run {
sb.append(name)
sb.append(argsStr())
sb.toString()
}

fun MethodItem.argsStr():String{
val sb = StringBuilder()
if(this is AbcMethod && codeItem != null){
val code = codeItem!!
val argCount = code.numArgs - 3
if(argCount >= 0){
sb.append("(FunctionObject, NewTarget, this")
repeat(argCount){
sb.append(", arg$it")
}
sb.append(')')
}
}
return sb.toString()
}
6 changes: 6 additions & 0 deletions abcdecoder/src/jvmMain/resources/ic/javaScript/javaScript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AbcMethod(abc: AbcBuf, offset: Int) :MethodItem(abc, offset){
}
val data:List<MethodTag> get() = _data.value

val codeItem: Code? by lazy {
val codeItem: Code? by WeakLazy {
data.firstOrNull { it is MethodTag.Code }?.let { Code(this,(it as MethodTag.Code).offset) }
}

Expand Down Expand Up @@ -189,8 +189,10 @@ sealed class MethodTag{
class RuntimeParamAnno(annoOffset: Int) :ParamAnnoTag(annoOffset)
class DbgInfo(method: AbcMethod, offset:Int): MethodTag(){
val info = DebugInfo(method.abc,offset)
val state = kotlin.runCatching { info.lineNumberProgram?.eval(info) }
.onFailure { it.printStackTrace() }.getOrNull()
val state by lazy {
kotlin.runCatching { info.lineNumberProgram?.eval(info) }
.onFailure { it.printStackTrace() }.getOrNull()
}

override fun toString(): String {
return "Dbg(lineStart=${info.lineStart},paramName=${info.params},cps=${info.constantPool},lnp=${info.lineNumberProgram?.eval(info)})"
Expand Down Expand Up @@ -223,4 +225,20 @@ sealed class MethodTag{
}
}
}
}

fun MethodItem.argsStr():String{
val sb = StringBuilder()
if(this is AbcMethod && codeItem != null){
val code = codeItem!!
val argCount = code.numArgs - 3
if(argCount >= 0){
sb.append("(FunctionObject, NewTarget, this")
repeat(argCount){
sb.append(", arg$it")
}
sb.append(')')
}
}
return sb.toString()
}
Loading