mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
refactor: improve code readability and selection behavior in markdown-code-run.ts
This commit is contained in:
@@ -171,6 +171,18 @@ const RunCode = defineComponent({
|
||||
runner.value = getAllRunners().find((runner) => runner.match(props.language!, props.firstLine!))
|
||||
}
|
||||
|
||||
const selectRunResult = (e: MouseEvent) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
const target = e.currentTarget as HTMLElement
|
||||
|
||||
const selection = target.ownerDocument.defaultView!.getSelection()
|
||||
const range = target.ownerDocument.createRange()
|
||||
range.selectNodeContents(e.currentTarget as HTMLElement)
|
||||
selection?.removeAllRanges()
|
||||
selection?.addRange(range)
|
||||
}
|
||||
|
||||
watchEffect(refreshRunner)
|
||||
registerHook('CODE_RUNNER_CHANGE', refreshRunner)
|
||||
|
||||
@@ -197,7 +209,7 @@ const RunCode = defineComponent({
|
||||
onClick: runInXterm
|
||||
}),
|
||||
]),
|
||||
h('div', { class: 'p-mcr-run-code-result skip-export', ref: resultRef }, h('output', { key: runResult, innerHTML: runResult })),
|
||||
h('div', { class: 'p-mcr-run-code-result skip-export', ref: resultRef }, h('output', { onDblclick: selectRunResult, key: runResult, innerHTML: runResult })),
|
||||
h('div', { class: 'p-mcr-clear-btn-wrapper skip-print' }, h(
|
||||
h(
|
||||
'div',
|
||||
|
||||
Reference in New Issue
Block a user