Skip to content

Commit 5987158

Browse files
Merge pull request #2028 from iamfaran/fix/2022-tab-spaces
[Fix]: #2022 Tab spacing issue in code editor
2 parents e5dc227 + b16f6c2 commit 5987158

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

client/packages/lowcoder/src/base/codeEditor/extensions.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
foldKeymap,
2828
indentOnInput,
2929
} from "@codemirror/language";
30-
import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
30+
import { defaultKeymap, history, historyKeymap, insertTab, indentLess, indentMore } from "@codemirror/commands";
3131
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
3232
import { Diagnostic, linter, lintKeymap } from "@codemirror/lint";
3333
import { type EditorState, Prec } from "@codemirror/state";
@@ -282,7 +282,20 @@ export function useFocusExtension(onFocus?: (focused: boolean) => void): [Extens
282282
}
283283

284284
function indentWithTabExtension(open?: boolean) {
285-
return open ?? true ? keymap.of([indentWithTab]) : [];
285+
if (!(open ?? true)) return [];
286+
return keymap.of([
287+
{
288+
key: "Tab",
289+
run: (view: EditorView) => {
290+
const { main } = view.state.selection;
291+
if (!main.empty && main.from !== main.to) {
292+
return indentMore(view);
293+
}
294+
return insertTab(view);
295+
},
296+
},
297+
{ key: "Shift-Tab", run: indentLess },
298+
]);
286299
}
287300

288301
export function lineNoExtension(showLineNumber?: boolean) {
@@ -493,26 +506,26 @@ export function useExtensions(props: CodeEditorProps) {
493506
basicSetup,
494507
defaultTheme,
495508
highlightJsExt,
496-
autocompletionExtension,
497509
focusExtension,
498510
lineNoExt,
499511
languageExt,
500512
onChangeExt,
501513
placeholderExt,
502514
indentWithTabExt,
515+
autocompletionExtension,
503516
tooltipExt,
504517
lintExt,
505518
iconExt,
506519
],
507520
[
508521
highlightJsExt,
509-
autocompletionExtension,
510522
focusExtension,
511523
lineNoExt,
512524
languageExt,
513525
onChangeExt,
514526
placeholderExt,
515527
indentWithTabExt,
528+
autocompletionExtension,
516529
tooltipExt,
517530
lintExt,
518531
iconExt,

0 commit comments

Comments
 (0)