fix(code): pressing tab while multiple lines are selected would replace with tab

This commit is contained in:
Elian Doran 2025-05-31 12:06:14 +03:00
parent 03de472a57
commit 9e3909a5f7
No known key found for this signature in database

View File

@ -24,6 +24,23 @@ const smartIndentWithTab: KeyBinding[] = [
// Step 1: Handle non-empty selections → replace with tab
if (selection.ranges.some(range => !range.empty)) {
// If multiple lines are selected, insert a tab character at the start of each line
// and move the cursor to the position after the tab character.
const linesCovered = new Set<number>();
for (const range of selection.ranges) {
const startLine = state.doc.lineAt(range.from);
const endLine = state.doc.lineAt(range.to);
for (let lineNumber = startLine.number; lineNumber <= endLine.number; lineNumber++) {
linesCovered.add(lineNumber);
}
}
if (linesCovered.size > 1) {
// Multiple lines are selected, indent each line.
return indentMore({ state, dispatch });
} else {
// Single line selection, replace with tab.
for (let range of selection.ranges) {
changes.push({ from: range.from, to: range.to, insert: "\t" });
newSelections.push(EditorSelection.cursor(range.from + 1));
@ -37,6 +54,8 @@ const smartIndentWithTab: KeyBinding[] = [
userEvent: "input"
})
);
}
return true;
}