Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Enable slash hints during IME input https://github.com/siyuan-note/siyuan/issues/19939

Daniel2c6edd3b0a47
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 305a3a721e..2992f89948 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -4472,6 +4472,9 @@ export class WYSIWYG {
window.siyuan.menus.menu.remove();
return;
}
+ if ([":", "(", "【", "(", "[", "{", "「", "『", "#", "/", "、"].includes(event.data)) {
+ protyle.hint.enableExtend = true;
+ }
// 输入法可能暂时清空选区或把光标放到编辑器根节点,候选更新不能触发选区修复。
if (event.isComposing || (isComposition && !isCommittedTextInput(event))) {
return;
@@ -4483,9 +4486,6 @@ export class WYSIWYG {
}
// 输入可能改变列宽,隐藏已有调整线,待鼠标重新命中列边界后定位。
blockElement.closest(".table")?.querySelector(".table__resize")?.setAttribute("style", "display:none");
- if ([":", "(", "【", "(", "[", "{", "「", "『", "#", "/", "、"].includes(event.data)) {
- protyle.hint.enableExtend = true;
- }
// 外接键盘的结束事件可能缺失,收到明确提交的文本后恢复输入处理。
// 跨块组合由其独立事务完成,不能在这里拆开提交。
if (isComposition && !crossBlockComposition && isCommittedTextInput(event)) {
diff --git a/app/tests/compositionCaret.test.js b/app/tests/compositionCaret.test.js
index 99e3d2baa6..add5d026e3 100644
--- a/app/tests/compositionCaret.test.js
+++ b/app/tests/compositionCaret.test.js
@@ -97,6 +97,7 @@ const rendererSource = () => {
.replace("export const getEditorRange =", "const readEditorRange =") +
"const getEditorRange = (element) => { editorRangeReads++; return readEditorRange(element); };" +
extract("wysiwyg/keydown", ["keydown"]) +
+ extract("util/tableVirtualizationDOM", ["TABLE_VIRTUAL_ID"]) +
extract("wysiwyg/transaction", ["updateTransaction"]) + `
export function checkMobileInput(event) {
let composing = true;
@@ -203,6 +204,29 @@ const runCases = async () => {
return {element, protyle, start, finish, flush, setRange, assertCaret};
};
let cases = 0;
+ for (const profile of profiles) {
+ for (const trigger of ["、", ":", ":", "【", "(", "/"]) {
+ const f = setup(paragraph("base"), profile);
+ f.protyle.hint.enableExtend = false;
+ const node = f.element.querySelector('[contenteditable="true"]').firstChild;
+ f.start(node, node.length);
+ node.appendData(trigger);
+ getSelection().removeAllRanges();
+ const reads = window.compositionCaret.getEditorRangeReads();
+ f.element.dispatchEvent(new InputEvent("input", {
+ bubbles: true, inputType: "insertCompositionText", data: trigger, isComposing: true,
+ }));
+ assert.equal(f.protyle.hint.enableExtend, trigger !== ":", profile.name + trigger);
+ assert.equal(window.compositionCaret.getEditorRangeReads(), reads, profile.name);
+ assert.equal(getSelection().rangeCount, 0);
+ assert.equal(f.protyle.inputs, 0);
+ f.setRange(node, node.length);
+ await f.finish(trigger);
+ assert.equal(f.protyle.inputs, 1);
+ assert.equal(f.protyle.hint.enableExtend, trigger !== ":");
+ cases++;
+ }
+ }
for (const profile of profiles) {
const f = setup(paragraph('<span data-type="inline-math" contenteditable="false">x</span>base'), profile);
const node = f.element.querySelector('[contenteditable="true"]').lastChild;
@@ -577,7 +601,7 @@ if (process.versions.electron && process.type === "browser") {
try {
const {stdout} = await require("node:util").promisify(require("node:child_process").execFile)(
require("electron"), [__filename, profile], {env, windowsHide: true, timeout: 40000});
- assert.match(stdout, /Composition caret: 50 Electron cases passed/);
+ assert.match(stdout, /Composition caret: 86 Electron cases passed/);
} finally {
assert.equal(path.dirname(path.resolve(profile)), path.resolve(os.tmpdir()));
assert.ok(path.basename(profile).startsWith("siyuan-composition-caret-"));