From 5c5d5e2b11f7958827addec4415630c752e91083 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 29 Nov 2023 16:45:23 +0800 Subject: [PATCH] fix: incremental insertion incorrect if input at block start (#3743) Co-authored-by: Johnson Chu --- packages/language-core/src/plugins/file-vue.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/language-core/src/plugins/file-vue.ts b/packages/language-core/src/plugins/file-vue.ts index 0b68671cb8..69dfbc02bf 100644 --- a/packages/language-core/src/plugins/file-vue.ts +++ b/packages/language-core/src/plugins/file-vue.ts @@ -22,16 +22,23 @@ const plugin: VueLanguagePlugin = (_ctx) => { ].filter((block): block is NonNullable => !!block); const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset); - if (!hitBlock) { return; } - hitBlock.content = + const oldContent = hitBlock.content; + const newContent = hitBlock.content = hitBlock.content.substring(0, change.start - hitBlock.loc.start.offset) + change.newText + hitBlock.content.substring(change.end - hitBlock.loc.start.offset); + // #3449 + const endTagRegex = new RegExp(``); + const insertedEndTag = !!oldContent.match(endTagRegex) !== !!newContent.match(endTagRegex); + if (insertedEndTag) { + return; + } + const lengthDiff = change.newText.length - (change.end - change.start); for (const block of blocks) {