From fdf3072babe3c02a530bfdaf2504a221f25f922a Mon Sep 17 00:00:00 2001 From: Gnohz Gniy <0x00eeee@gmail.com> Date: Mon, 27 Feb 2023 10:50:14 +0800 Subject: [PATCH] Fix interceptInputs for languages with diacritics (#87) --- CoreEditor/src/modules/input/wrapBlock.ts | 5 +++++ CoreEditor/src/styling/nodes/selection.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CoreEditor/src/modules/input/wrapBlock.ts b/CoreEditor/src/modules/input/wrapBlock.ts index 00d69144..bbe96fe2 100644 --- a/CoreEditor/src/modules/input/wrapBlock.ts +++ b/CoreEditor/src/modules/input/wrapBlock.ts @@ -7,6 +7,11 @@ import { EditorView } from '@codemirror/view'; * @param mark The mark, e.g., "*" */ export default function wrapBlock(mark: string, editor: EditorView) { + // Fallback to the default behavior if all selections are empty + if (!editor.state.selection.ranges.some(range => !range.empty)) { + return false; + } + const doc = editor.state.doc; editor.dispatch(editor.state.changeByRange(({ from, to }) => { const selection = doc.sliceString(from, to); diff --git a/CoreEditor/src/styling/nodes/selection.ts b/CoreEditor/src/styling/nodes/selection.ts index 9f50cf1d..e1a2d196 100644 --- a/CoreEditor/src/styling/nodes/selection.ts +++ b/CoreEditor/src/styling/nodes/selection.ts @@ -19,7 +19,7 @@ export const selectedTextDecoration = ViewPlugin.fromClass(class { return; } - const ranges = update.state.selection.ranges.filter(range => range.to !== range.from); + const ranges = update.state.selection.ranges.filter(range => !range.empty); const markDeco = Decoration.mark({ class: 'cm-selectedTextRange' }); this.decorations = Decoration.set(ranges.map(range => { return markDeco.range(range.from, range.to);