Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

fix(editor): layout-independent list shortcuts, always-fenced code block (#613)

Dipak Chaudharie3b5def10d47
diff --git a/frontend/app/components/MarkdownEditor/modules/editorCommands.ts b/frontend/app/components/MarkdownEditor/modules/editorCommands.ts
index da8c1ede..c0faad31 100644
--- a/frontend/app/components/MarkdownEditor/modules/editorCommands.ts
+++ b/frontend/app/components/MarkdownEditor/modules/editorCommands.ts
@@ -318,21 +318,14 @@ function toggleCodeBlock(view: EditorView, language = ''): void {
}
}
- // Not in a code block, create one
- const isMultiLine = selectedText.includes('\n');
-
- if (isMultiLine || selectedText.length > 50) {
- // Use fenced code block for multi-line
- const insert = `\`\`\`${language}\n${selectedText}\n\`\`\``;
- view.dispatch({
- changes: { from, to, insert },
- selection: { anchor: from + 4 + language.length, head: from + 4 + language.length + selectedText.length },
- });
- } else {
- // Use inline code for short single-line
- toggleInlineFormat(view, 'code');
- return;
- }
+ // Not in a code block, create one. Always a FENCED block (#610): inline code has its own
+ // shortcut and toolbar button, so silently degrading short selections to `inline` made the
+ // explicit code-block action look broken.
+ const insert = `\`\`\`${language}\n${selectedText}\n\`\`\``;
+ view.dispatch({
+ changes: { from, to, insert },
+ selection: { anchor: from + 4 + language.length, head: from + 4 + language.length + selectedText.length },
+ });
view.focus();
}
diff --git a/frontend/app/components/MarkdownEditor/modules/editorKeymaps.ts b/frontend/app/components/MarkdownEditor/modules/editorKeymaps.ts
index 5171c572..a116365a 100644
--- a/frontend/app/components/MarkdownEditor/modules/editorKeymaps.ts
+++ b/frontend/app/components/MarkdownEditor/modules/editorKeymaps.ts
@@ -222,6 +222,33 @@ export function createKeymaps(commands: { exec: (action: string, payload?: strin
return true;
},
},
+
+ // Layout-independent fallback for the Mod-Shift-digit list shortcuts (#610): with Shift held,
+ // the digit row produces a different character on many layouts ('&' on QWERTY, '/' on QWERTZ…)
+ // and some browser/layout combos report keyCodes that CodeMirror can't map back to the digit,
+ // so the name-based bindings above never match. Matching the PHYSICAL key (event.code) works
+ // on every layout; it only runs when no named binding handled the event, so there's no double
+ // dispatch. Returning true makes CodeMirror preventDefault, which also stops the browser's own
+ // Ctrl+digit fallbacks (tab switching) on layouts where digits are shifted.
+ {
+ any: (_view, event) => {
+ if (!(event.ctrlKey || event.metaKey) || !event.shiftKey || event.altKey) return false;
+ // The numeric keypad reports its own codes, so it needs listing alongside the digit row.
+ const digitActions: Record<string, string> = {
+ Digit7: 'orderedList',
+ Numpad7: 'orderedList',
+ Digit8: 'list',
+ Numpad8: 'list',
+ Digit9: 'taskList',
+ Numpad9: 'taskList',
+ };
+ const action = digitActions[event.code];
+ if (!action) return false;
+ commands.exec(action);
+ return true;
+ },
+ stopPropagation: true,
+ },
];
return markdownKeysmap;