From 65ddc0f000dadc9aad7d1b4c5efb1e8eff97b7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E4=BB=99=E9=83=BD=E6=B2=A1=E7=94=A8?= <615206459@qq.com> Date: Sun, 4 Feb 2024 20:46:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/helper/views/plugins/serve.vue | 32 +++++++++++++++++-- src/modules/space/components/space.vue | 2 +- .../editor-monaco/components/monaco.vue | 26 +++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/modules/helper/views/plugins/serve.vue b/src/modules/helper/views/plugins/serve.vue index 9cdd301..bdd241e 100644 --- a/src/modules/helper/views/plugins/serve.vue +++ b/src/modules/helper/views/plugins/serve.vue @@ -74,7 +74,22 @@ - + + + @@ -134,10 +149,18 @@ function toSet(item: Eps.PluginInfoEntity) { component: { name: "cl-editor", props: { - name: "cl-editor-monaco" + name: "cl-editor-monaco", + ref: setRefs("editor") } } }, + { + label: " ", + flex: false, + component: { + name: "slot-upload" + } + }, { label: "状态", prop: "status", @@ -192,6 +215,11 @@ function toDel(item: Eps.PluginInfoEntity, index: number) { .catch(() => null); } +// 文件选择 +function onFileConfirm(arr: any[]) { + refs.editor.appendContent(arr[0]?.url); +} + // 状态修改 function onStatusChange(item: Eps.PluginInfoEntity) { service.plugin.info diff --git a/src/modules/space/components/space.vue b/src/modules/space/components/space.vue index f4c90ac..dd2d8ee 100644 --- a/src/modules/space/components/space.vue +++ b/src/modules/space/components/space.vue @@ -4,7 +4,7 @@ diff --git a/src/plugins/editor-monaco/components/monaco.vue b/src/plugins/editor-monaco/components/monaco.vue index 139c219..efb256e 100644 --- a/src/plugins/editor-monaco/components/monaco.vue +++ b/src/plugins/editor-monaco/components/monaco.vue @@ -73,6 +73,31 @@ function setContent(value: string = "") { } } +// 光标后追加内容 +function appendContent(text: string = "") { + const position = editor?.getPosition(); + + if (position) { + editor?.executeEdits("", [ + { + range: new monaco.Range( + position.lineNumber, + position.column, + position.lineNumber, + position.column + ), + text + } + ]); + + editor?.setPosition({ + lineNumber: position.lineNumber, + column: position.column + text.length + }); + editor?.focus(); + } +} + // 格式化内容 async function formatCode() { await editor?.getAction("editor.action.formatDocument")?.run(); @@ -164,6 +189,7 @@ onUnmounted(() => { defineExpose({ editor, setContent, + appendContent, formatCode });