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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-encoder",
"private": true,
"version": "4.7.0",
"version": "4.7.1",
"type": "module",
"scripts": {
"start": "bash src/scripts/start.sh",
Expand Down
14 changes: 7 additions & 7 deletions src/utils/config/template/code/vue-component/code.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
</template>

<script>
export default {
data() {
return {
message: "This is a template of Vue3 Component!",
}
},
}
export default {
data() {
return {
message: "This is a template of Vue3 Component!",
}
},
}
</script>

<style scoped></style>
3 changes: 2 additions & 1 deletion src/utils/editor/config/editor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { tsTypeDefinition, typescriptLSPPlugin } from "../lsp/typescript"
import { indentationMarkers } from "@replit/codemirror-indentation-markers"
import { getGoToLinePanel } from "../panels/go-to-line"
import { getFormatCodeKeymap, prep2ParserNameMap } from "../formatter"
import { vueLanguageNoIndent } from "../indentation"

/** 快捷键模式对应的按键映射扩展 */
export const ShortCutMode2ExtensionMap = {
Expand Down Expand Up @@ -56,7 +57,7 @@ const Prep2DefaultExtensionMap: Record<Prep, () => Extension[]> = {
[Prep.TYPESCRIPT]: () => [typescriptLSPPlugin],
[Prep.BABEL]: () => [],
[Prep.COFFEESCRIPT]: () => [],
[Prep.VUE]: () => [],
[Prep.VUE]: () => [vueLanguageNoIndent],
}

/** 获取每个预处理器的默认配置 */
Expand Down
15 changes: 15 additions & 0 deletions src/utils/editor/indentation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { htmlLanguage } from "@codemirror/lang-html"
import { TreeIndentContext, indentNodeProp } from "@codemirror/language"

/** vue 单文件组件的 script 和 style 不应有第一层默认缩进,需要去掉 */
export const vueLanguageNoIndent = htmlLanguage.configure({
props: [indentNodeProp.add({
Element(context: TreeIndentContext) {
const after = /^(\s*)(<\/)?/.exec(context.textAfter)
if (!after || (context.node.to <= context.pos + after[0].length)) { return context.continue() }
// 检查是否在 script 或 style 节点内得出是否需要缩进
const noIndent = context.node.getChild("Script") || context.node.getChild("StyleSheet")
return context.lineIndent(context.node.from) + (noIndent || after[2] ? 0 : context.unit)
},
})],
})