@@ -27,7 +27,7 @@ import {
27
27
foldKeymap ,
28
28
indentOnInput ,
29
29
} from "@codemirror/language" ;
30
- import { defaultKeymap , history , historyKeymap , indentWithTab } from "@codemirror/commands" ;
30
+ import { defaultKeymap , history , historyKeymap , insertTab , indentLess , indentMore } from "@codemirror/commands" ;
31
31
import { highlightSelectionMatches , searchKeymap } from "@codemirror/search" ;
32
32
import { Diagnostic , linter , lintKeymap } from "@codemirror/lint" ;
33
33
import { type EditorState , Prec } from "@codemirror/state" ;
@@ -282,7 +282,20 @@ export function useFocusExtension(onFocus?: (focused: boolean) => void): [Extens
282
282
}
283
283
284
284
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
+ ] ) ;
286
299
}
287
300
288
301
export function lineNoExtension ( showLineNumber ?: boolean ) {
@@ -493,26 +506,26 @@ export function useExtensions(props: CodeEditorProps) {
493
506
basicSetup ,
494
507
defaultTheme ,
495
508
highlightJsExt ,
496
- autocompletionExtension ,
497
509
focusExtension ,
498
510
lineNoExt ,
499
511
languageExt ,
500
512
onChangeExt ,
501
513
placeholderExt ,
502
514
indentWithTabExt ,
515
+ autocompletionExtension ,
503
516
tooltipExt ,
504
517
lintExt ,
505
518
iconExt ,
506
519
] ,
507
520
[
508
521
highlightJsExt ,
509
- autocompletionExtension ,
510
522
focusExtension ,
511
523
lineNoExt ,
512
524
languageExt ,
513
525
onChangeExt ,
514
526
placeholderExt ,
515
527
indentWithTabExt ,
528
+ autocompletionExtension ,
516
529
tooltipExt ,
517
530
lintExt ,
518
531
iconExt ,
0 commit comments