给monoca添加placeholder

This commit is contained in:
fofolee 2022-04-13 13:24:01 +08:00
parent faa83ca7f0
commit 8f479fa545
2 changed files with 54 additions and 27 deletions

View File

@ -117,7 +117,6 @@
><q-tooltip>脚本及输出编码设置</q-tooltip></q-btn ><q-tooltip>脚本及输出编码设置</q-tooltip></q-btn
> >
<q-separator vertical inset /> <q-separator vertical inset />
<q-btn <q-btn
dense dense
flat flat
@ -140,39 +139,28 @@
</div> </div>
</div> </div>
</div> </div>
<MonocaEditor <MonacoEditor
class="absolute-bottom" class="absolute-bottom"
ref="editor" ref="editor"
@typing="(val) => (quickcommandInfo.cmd = val)"
:style="{ :style="{
top: languageBarHeight + 'px', top: languageBarHeight + 'px',
left: editorLeft, left: this.action.type === 'run' ? 0 : this.sideBarWidth + 'px',
transition: '0.3s', transition: '0.3s',
}" }"
/> />
<div
class="absolute-bottom flex justify-center content-center"
:style="{
top: languageBarHeight + 'px',
left: editorLeft,
userSelect: 'none',
}"
>
ctrl + s 保存 <br />
ctrl + b 运行 <br />
alt + z 自动换行
</div>
<!-- 运行结果 --> <!-- 运行结果 -->
<CommandRunResult :action="action" ref="result"></CommandRunResult> <CommandRunResult :action="action" ref="result"></CommandRunResult>
</div> </div>
</template> </template>
<script> <script>
import MonocaEditor from "components/MonocaEditor"; import MonacoEditor from "components/MonacoEditor";
import CommandSideBar from "components/CommandSideBar"; import CommandSideBar from "components/CommandSideBar";
import CommandRunResult from "components/CommandRunResult"; import CommandRunResult from "components/CommandRunResult";
export default { export default {
components: { MonocaEditor, CommandSideBar, CommandRunResult }, components: { MonacoEditor, CommandSideBar, CommandRunResult },
data() { data() {
return { return {
programLanguages: Object.keys(this.$programmings), programLanguages: Object.keys(this.$programmings),
@ -217,9 +205,6 @@ export default {
"搜索结果" "搜索结果"
); );
}, },
editorLeft() {
return this.action.type === "run" ? "0" : this.sideBarWidth + "px";
},
}, },
created() {}, created() {},
methods: { methods: {
@ -231,7 +216,7 @@ export default {
?.codeHistory ?.codeHistory
: this.action.data; : this.action.data;
_.merge(this.quickcommandInfo, quickCommandInfo); _.merge(this.quickcommandInfo, quickCommandInfo);
// monoca // monaco
this.$refs.editor.setEditorValue(this.quickcommandInfo.cmd); this.$refs.editor.setEditorValue(this.quickcommandInfo.cmd);
this.setLanguage(this.quickcommandInfo.program); this.setLanguage(this.quickcommandInfo.program);
// //

View File

@ -1,5 +1,16 @@
<template> <template>
<div id="monocaEditor"></div> <div>
<div id="monacoEditor" style="width: 100%; height: 100%"></div>
<div class="absolute-center flex" v-show="!value">
<div class="placeholder text-center q-gutter-md">
<div v-for="shortCut in shortCuts" :key="shortCut">
<span>{{ shortCut[0] }}</span
><span class="shortcut-key">{{ shortCut[1] }}</span
><span class="shortcut-key">{{ shortCut[2] }}</span>
</div>
</div>
</div>
</div>
</template> </template>
<script> <script>
@ -17,12 +28,20 @@ let languageCompletions = importAll(
require.context("../plugins/monaco/completions/", false, /\.js$/) require.context("../plugins/monaco/completions/", false, /\.js$/)
); );
let cmdCtrlKey = utools.isMacOs() ? "⌘" : "Ctrl";
let optAltKey = utools.isMacOs() ? "⌥" : "Alt";
export default { export default {
data() { data() {
return { return {
editor: null, editor: null,
value: null,
wordWrap: "off", wordWrap: "off",
commandString: this.$q.platform.is.mac ? "⌘" : "ctrl", shortCuts: [
["保存", cmdCtrlKey, "S"],
["运行", cmdCtrlKey, "B"],
["换行", optAltKey, "Z"],
],
}; };
}, },
mounted() { mounted() {
@ -49,13 +68,13 @@ export default {
}, },
}; };
this.editor = monaco.editor.create( this.editor = monaco.editor.create(
document.getElementById("monocaEditor"), document.getElementById("monacoEditor"),
monacoEditorPreferences monacoEditorPreferences
); );
this.loadTypes(); this.loadTypes();
this.registerLanguage(); this.registerLanguage();
this.setEditorTheme(); this.setEditorTheme();
this.listenEditroValue(); this.listenEditorValue();
this.bindKeys(); this.bindKeys();
}, },
loadTypes() { loadTypes() {
@ -177,9 +196,11 @@ export default {
destoryEditor() { destoryEditor() {
this.rawEditor.dispose(); this.rawEditor.dispose();
}, },
listenEditroValue() { listenEditorValue() {
this.rawEditor.focus();
this.rawEditor.onDidChangeModelContent(() => { this.rawEditor.onDidChangeModelContent(() => {
this.$parent.quickcommandInfo.cmd = this.getEditorValue(); this.value = this.getEditorValue();
this.$emit("typing", this.value);
}); });
}, },
bindKeys() { bindKeys() {
@ -207,3 +228,24 @@ export default {
}, },
}; };
</script> </script>
<style scoped>
.placeholder {
font-size: 12px;
font-family: sans-serif;
color: #a3a3a3;
user-select: none;
}
.shortcut-key {
background-color: #f3f4f6;
border-radius: 0.25rem;
margin-left: 0.5rem;
padding-left: 0.25rem;
padding-right: 0.25rem;
transition-property: background-color, border-color, color, fill, stroke,
opacity, box-shadow, -webkit-box-shadow, transform, -webkit-transform,
filter, backdrop-filter;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
}
</style>