fix(项目设置): 代码模版生成的代码添加至脚本编辑器光标位置

--bug=1002574 --user=李玉号 【github】缺陷记录2021-04-12
https://www.tapd.cn/55049933/s/1173839
This commit is contained in:
shiziyuan9527 2022-06-06 15:21:27 +08:00 committed by shiziyuan9527
parent 1689b29b02
commit 9becbe564d
4 changed files with 18 additions and 14 deletions

View File

@ -218,12 +218,9 @@ export default {
} }
}, },
handleCodeTemplate(code) { handleCodeTemplate(code) {
if (!this.jsr223ProcessorData.script) { if (this.$refs.codeEdit) {
this.jsr223ProcessorData.script = code; this.$refs.codeEdit.insert(code);
} else {
this.jsr223ProcessorData.script = this.jsr223ProcessorData.script + '\n' + code;
} }
this.reload();
}, },
} }
} }

View File

@ -1,9 +1,9 @@
<template> <template>
<editor v-model="formatData" :lang="mode" @init="editorInit" :theme="theme" :height="height" :key="readOnly"/> <editor v-model="formatData" :lang="mode" @init="editorInit" :theme="theme" :height="height" :key="readOnly" ref="msEditor"/>
</template> </template>
<script> <script>
import {formatHtml, formatJson, formatXml} from "../../../../../common/js/format-utils"; import {formatJson, formatXml} from "../../../../../common/js/format-utils";
import toDiffableHtml from 'diffable-html'; import toDiffableHtml from 'diffable-html';
export default { export default {
@ -65,6 +65,11 @@
} }
}, },
methods: { methods: {
insert(code) {
if (this.$refs.msEditor.editor) {
this.$refs.msEditor.editor.insert(code);
}
},
editorInit: function (editor) { editorInit: function (editor) {
require('brace/ext/language_tools') //language extension prerequsite... require('brace/ext/language_tools') //language extension prerequsite...
this.modes.forEach(mode => { this.modes.forEach(mode => {

View File

@ -1,9 +1,9 @@
<template> <template>
<editor v-model="formatData" :lang="mode" @init="editorInit" :theme="theme" :height="height"/> <editor v-model="formatData" :lang="mode" @init="editorInit" :theme="theme" :height="height" ref="msEditor"/>
</template> </template>
<script> <script>
import {formatHtml, formatJson, formatXml} from "../../../../common/js/format-utils"; import {formatJson, formatXml} from "../../../../common/js/format-utils";
import toDiffableHtml from 'diffable-html'; import toDiffableHtml from 'diffable-html';
export default { export default {
@ -70,6 +70,11 @@
} }
}, },
methods: { methods: {
insert(code) {
if (this.$refs.msEditor.editor) {
this.$refs.msEditor.editor.insert(code);
}
},
editorInit: function (editor) { editorInit: function (editor) {
require('brace/ext/language_tools') //language extension prerequsite... require('brace/ext/language_tools') //language extension prerequsite...
this.modes.forEach(mode => { this.modes.forEach(mode => {

View File

@ -210,12 +210,9 @@ export default {
} }
}, },
handleCodeTemplate(code) { handleCodeTemplate(code) {
if (!this.form.script) { if (this.$refs.codeEdit) {
this.form.script = code; this.$refs.codeEdit.insert(code);
} else {
this.form.script = this.form.script + '\n' + code;
} }
this.reloadCodeEdit();
}, },
reload() { reload() {
this.isFormAlive = false; this.isFormAlive = false;