Skip to content

Commit b97dfe4

Browse files
committed
fix: indentation breaks when pasting a copied element
1 parent 8e349d2 commit b97dfe4

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -390,27 +390,11 @@ define(function (require, exports, module) {
390390
if (!text) {
391391
return;
392392
}
393+
// get the indentation in the target line and check if there is any real indentation
394+
let indent = editor.getTextBetween({ line: startPos.line, ch: 0 }, startPos);
395+
indent = indent.trim() === '' ? indent : '';
393396

394-
// get the indentation at the target element's line
395-
const indent = editor.getTextBetween({ line: startPos.line, ch: 0 }, startPos);
396-
397-
// for proper indentation
398-
const lines = text.split('\n');
399-
const indentedLines = lines.map((line, index) => {
400-
if (index === 0) {
401-
return indent.trim() === "" ? indent + line : line;
402-
}
403-
return line ? indent + line : line;
404-
});
405-
const indentedContent = indentedLines.join('\n');
406-
407-
editor.document.batchOperation(function () {
408-
if (indent.trim() === "") {
409-
editor.replaceRange(indentedContent + "\n", startPos);
410-
} else {
411-
editor.replaceRange("\n" + indentedContent, { line: startPos.line, ch: 0 });
412-
}
413-
});
397+
editor.replaceRange(text + '\n' + indent, startPos);
414398
}).catch(err => {
415399
console.error("Failed to read from clipboard:", err);
416400
});

0 commit comments

Comments
 (0)