Skip to content

Commit 5c5be80

Browse files
committed
fix: indent of target element after drag & drop operation
1 parent a312acb commit 5c5be80

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ define(function (require, exports, module) {
178178
return;
179179
}
180180
const targetText = editor.getTextBetween(targetRange.from, targetRange.to);
181-
182-
// sourceText + targetText is done so that new source text can maintain the indentation
183-
editor.replaceRange(sourceText + targetText, targetRange.from, targetRange.to);
181+
const targetIndent = editor.getTextBetween({ line: targetRange.from.line, ch: 0 }, targetRange.from);
182+
183+
// to check if there is only indentation and no text before it
184+
if (targetIndent.trim() === "") {
185+
const finalText = sourceText + '\n' + targetIndent + targetText;
186+
editor.replaceRange(finalText, targetRange.from, targetRange.to);
187+
} else {
188+
editor.replaceRange(sourceText + targetText, targetRange.from, targetRange.to);
189+
}
184190
});
185191
}
186192

0 commit comments

Comments
 (0)