From 0208550ca38f4f9a3b2a318a53d0822b3c0f0686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 13 Apr 2026 17:27:06 +0200 Subject: [PATCH] fix tab indent issue --- client/components/codeEditor/customKeyMaps.js | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/client/components/codeEditor/customKeyMaps.js b/client/components/codeEditor/customKeyMaps.js index dca6dded1..4bf1142ae 100644 --- a/client/components/codeEditor/customKeyMaps.js +++ b/client/components/codeEditor/customKeyMaps.js @@ -1,26 +1,6 @@ /* eslint max-lines: ["error", { "max": 300 }] */ import { keymap } from '@codemirror/view'; -import { undo, redo } from '@codemirror/commands'; - -const insertTabAtCursor = (view)=>{ - const { from } = view.state.selection.main; - view.dispatch({ - changes : { from, insert: ' ' }, - selection : { anchor: from + 1 } - }); - return true; -}; - -const indentMore = (view)=>{ - const { from, to } = view.state.selection.main; - const lines = []; - for (let l = view.state.doc.lineAt(from).number; l <= view.state.doc.lineAt(to).number; l++) { - const line = view.state.doc.line(l); - lines.push({ from: line.from, to: line.from, insert: ' ' }); // 2 spaces for tab - } - view.dispatch({ changes: lines }); - return true; -}; +import { undo, redo, indentMore } from '@codemirror/commands'; const indentLess = (view)=>{ const { from, to } = view.state.selection.main; @@ -208,7 +188,7 @@ const newPage = (view)=>{ }; export const generalKeymap = keymap.of([ - { key: 'Tab', run: insertTabAtCursor }, + { key: 'Tab', run: indentMore }, { key: 'Mod-z', run: undo }, //i think it may be unnecessary { key: 'Mod-Shift-z', run: redo }, ]); @@ -238,4 +218,5 @@ export const markdownKeymap = keymap.of([ { key: 'Shift-Mod-6', run: makeHeader(6) }, { key: 'Shift-Mod-Enter', run: newColumn }, { key: 'Mod-Enter', run: newPage }, + ]);