Skip to content

Commit

Permalink
handle multipe selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jczhong84 committed Nov 22, 2024
1 parent 101b0a9 commit faa1336
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ const handleTabKey =
}

// Insert 2 or 4 spaces instead of a real tab to reach the next tab stop
const line = state.doc.lineAt(state.selection.main.from);
const column = state.selection.main.from - line.from;
const spacesToInsert = tabSize - (column % tabSize);
const changes = state.changeByRange((range) => {
const line = state.doc.lineAt(range.from);
const column = range.from - line.from;
const spacesToInsert = tabSize - (column % tabSize);

let changes = state.changeByRange((range) => ({
changes: {
from: range.from,
to: range.to,
insert: ' '.repeat(spacesToInsert),
},
range: EditorSelection.cursor(range.from + spacesToInsert),
}));
return {
changes: {
from: range.from,
to: range.to,
insert: ' '.repeat(spacesToInsert),
},
range: EditorSelection.cursor(range.from + spacesToInsert),
};
});

dispatch(state.update(changes, { userEvent: 'input' }));
return true;
Expand Down

0 comments on commit faa1336

Please sign in to comment.