From 68b085b459d39630b707847d7c15670621728b41 Mon Sep 17 00:00:00 2001 From: oeyoews Date: Sun, 31 Dec 2023 03:14:28 +0800 Subject: [PATCH] update --- src/tiddlywiki-codemirror-6/engine.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/tiddlywiki-codemirror-6/engine.ts b/src/tiddlywiki-codemirror-6/engine.ts index d8703ad9..2927ff51 100644 --- a/src/tiddlywiki-codemirror-6/engine.ts +++ b/src/tiddlywiki-codemirror-6/engine.ts @@ -8,7 +8,8 @@ import { indentOnInput, bracketMatching, foldGutter, - foldKeymap + foldKeymap, + language } from '@codemirror/language'; import { html, htmlLanguage } from '@codemirror/lang-html'; @@ -23,7 +24,12 @@ import { import { javascript, javascriptLanguage } from '@codemirror/lang-javascript'; -import { EditorState, EditorSelection, Prec } from '@codemirror/state'; +import { + Compartment, + EditorState, + EditorSelection, + Prec +} from '@codemirror/state'; import { searchKeymap, @@ -192,6 +198,7 @@ class CodeMirrorEngine { ) ); + // 检测文档大小 const docSizePlugin = ViewPlugin.fromClass( class { constructor(view) { @@ -211,9 +218,23 @@ class CodeMirrorEngine { } } ); + const languageConf = new Compartment(); + + // 自动语言检测 + const autoLanguage = EditorState.transactionExtender.of((tr) => { + if (!tr.docChanged) return null; + let docIsHTML = /^\s*