From faa13365be206bc4b0a95c946b33097cd954beec Mon Sep 17 00:00:00 2001 From: "J.C. Zhong" Date: Fri, 22 Nov 2024 02:01:11 +0000 Subject: [PATCH] handle multipe selection --- .../extensions/useOptionsExtension.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/querybook/webapp/hooks/queryEditor/extensions/useOptionsExtension.ts b/querybook/webapp/hooks/queryEditor/extensions/useOptionsExtension.ts index e8c64a203..4128f7e86 100644 --- a/querybook/webapp/hooks/queryEditor/extensions/useOptionsExtension.ts +++ b/querybook/webapp/hooks/queryEditor/extensions/useOptionsExtension.ts @@ -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;