Skip to content

Commit a19a479

Browse files
committed
add support for tab for accepting completions
1 parent 9e41faa commit a19a479

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/editor-codemirror/src/behaviors/indent.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,29 @@
1313
*
1414
*/
1515

16-
import { indentWithTab } from "@codemirror/commands";
16+
import { indentLess, indentMore } from "@codemirror/commands";
1717

1818
import { indentOnInput } from "@codemirror/language";
1919
import { keymap } from "@codemirror/view";
2020

2121
import { Behavior } from ".";
22+
import { acceptCompletion, completionStatus } from "@codemirror/autocomplete";
2223

23-
export function indentBehavior() : Behavior {
24+
export function tabBehavior(): Behavior {
2425
return {
2526
extensions: [
2627
indentOnInput(),
27-
keymap.of([indentWithTab])
28+
keymap.of([
29+
{
30+
key: 'Tab',
31+
preventDefault: true,
32+
shift: indentLess,
33+
run: e => {
34+
if (!completionStatus(e.state)) return indentMore(e);
35+
return acceptCompletion(e);
36+
},
37+
},
38+
])
2839
]
29-
}
40+
};
3041
}

packages/editor-codemirror/src/behaviors/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { CodeViewOptions, ExtensionContext } from "editor";
2727
import { langModeBehavior } from './langmode';
2828
import { keyboardBehavior } from './keyboard';
2929
import { findBehavior } from './find';
30-
import { indentBehavior } from './indent';
30+
import { tabBehavior } from './indent';
3131
import { trackSelectionBehavior } from './trackselection';
3232
import { themeBehavior } from './theme';
3333
import { prefsBehavior } from './prefs';
@@ -63,7 +63,7 @@ export function createBehaviors(context: BehaviorContext): Behavior[] {
6363
langModeBehavior(context),
6464
completionBehavior(context),
6565
findBehavior(context),
66-
indentBehavior(),
66+
tabBehavior(),
6767
themeBehavior(context),
6868
prefsBehavior(context),
6969
trackSelectionBehavior(context),

0 commit comments

Comments
 (0)