From 4bb582bdd8d1981cae58bbe76a26cc04b85bd8fe Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 24 Apr 2023 10:34:00 +0100 Subject: [PATCH] [cm6] Improve Tab behaviour in read-only mode (#12715) * Improve Tab behaviour in read-only mode * Remove Tab shortcuts from Markdown configuration GitOrigin-RevId: 9eb804fcf820b37b371b1c351cfbdf7bff1ced89 --- .../js/features/source-editor/commands/indent.ts | 3 +++ .../js/features/source-editor/extensions/shortcuts.ts | 2 -- .../source-editor/languages/markdown/shortcuts.ts | 11 ----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/commands/indent.ts b/services/web/frontend/js/features/source-editor/commands/indent.ts index ff5ce705b7..42cc66afff 100644 --- a/services/web/frontend/js/features/source-editor/commands/indent.ts +++ b/services/web/frontend/js/features/source-editor/commands/indent.ts @@ -3,6 +3,9 @@ import { getIndentUnit, indentString, indentUnit } from '@codemirror/language' import { EditorView } from '@codemirror/view' export const indentMore = (view: EditorView) => { + if (view.state.readOnly) { + return false + } view.dispatch( view.state.changeByRange(range => { const doc = view.state.doc diff --git a/services/web/frontend/js/features/source-editor/extensions/shortcuts.ts b/services/web/frontend/js/features/source-editor/extensions/shortcuts.ts index 14a0b1e2b1..01b84bf199 100644 --- a/services/web/frontend/js/features/source-editor/extensions/shortcuts.ts +++ b/services/web/frontend/js/features/source-editor/extensions/shortcuts.ts @@ -43,12 +43,10 @@ export const shortcuts = () => { const keyBindings: KeyBinding[] = [ { key: 'Tab', - preventDefault: true, run: indentMore, }, { key: 'Shift-Tab', - preventDefault: true, run: indentLess, }, { diff --git a/services/web/frontend/js/features/source-editor/languages/markdown/shortcuts.ts b/services/web/frontend/js/features/source-editor/languages/markdown/shortcuts.ts index 157d02ea9c..8ccadc2224 100644 --- a/services/web/frontend/js/features/source-editor/languages/markdown/shortcuts.ts +++ b/services/web/frontend/js/features/source-editor/languages/markdown/shortcuts.ts @@ -1,7 +1,6 @@ import { Prec } from '@codemirror/state' import { keymap } from '@codemirror/view' import { wrapRanges } from '../../commands/ranges' -import { indentLess, indentMore } from '@codemirror/commands' export const shortcuts = () => { return Prec.high( @@ -18,16 +17,6 @@ export const shortcuts = () => { preventDefault: true, run: wrapRanges('_', '_'), }, - { - key: 'Tab', - preventDefault: true, - run: indentMore, - }, - { - key: 'Shift-Tab', - preventDefault: true, - run: indentLess, - }, ]) ) }