Skip to content

Commit

Permalink
fix: incremental insertion incorrect if input at block start (#3743)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnson Chu <[email protected]>
  • Loading branch information
so1ve and johnsoncodehk authored Nov 29, 2023
1 parent dc2432f commit 32fd1ee
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/language-core/src/plugins/file-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ const plugin: VueLanguagePlugin = (_ctx) => {
].filter((block): block is NonNullable<typeof block> => !!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(`</\\s*${hitBlock.type}\\s*>`);
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) {
Expand Down

0 comments on commit 32fd1ee

Please sign in to comment.