An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Scroll cursor context after line breaks https://github.com/siyuan-note/siyuan/issues/19901
Daniel78984f4b63a1
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.tsindex fd70a4ee1d..f8048557cd 100644--- a/app/src/protyle/wysiwyg/input.ts+++ b/app/src/protyle/wysiwyg/input.ts@@ -585,7 +585,8 @@ export const input = async (...args: Parameters<typeof inputBlock>) => {} finally {resume();}- if (args[0].options.typewriterMode) {+ if (args[0].options.typewriterMode && !args[4]?.isComposing &&+ ["insertParagraph", "insertLineBreak"].includes(args[4]?.inputType)) {scheduleCaretScroll(args[0], "down");}};diff --git a/app/src/protyle/wysiwyg/inputCaretScroll.test.ts b/app/src/protyle/wysiwyg/inputCaretScroll.test.tsnew file mode 100644index 0000000000..94d74057f3--- /dev/null+++ b/app/src/protyle/wysiwyg/inputCaretScroll.test.ts@@ -0,0 +1,34 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import {join} from "node:path";+import {test} from "node:test";+import {ScriptTarget, transpileModule} from "typescript";++test("input reserves cursor context after line breaks, not ordinary typing or composition", async () => {+ const source = readFileSync(join(__dirname, "input.ts"), "utf8");+ const body = source.slice(source.indexOf("export const input ="), source.indexOf("const updateInput ="));+ for (const inputType of [undefined, "insertText", "insertCompositionText", "deleteContentBackward",+ "insertParagraph", "insertLineBreak"]) {+ for (const isComposing of [false, true]) {+ for (const typewriterMode of [false, true]) {+ const events: string[] = [];+ const protyle = {wysiwyg: {element: {}}, options: {typewriterMode}};+ const input = new Function("inputBlock", "suspendLongTextRuns", "scheduleCaretScroll",+ transpileModule(body.replace("export const", "const"), {+ compilerOptions: {target: ScriptTarget.ES2021},+ }).outputText + "\nreturn input;")(+ async () => { events.push("input"); },+ () => () => { events.push("resume"); },+ (owner: unknown, direction: string) => {+ assert.equal(owner, protyle);+ assert.equal(direction, "down");+ events.push("scroll");+ });+ await input(protyle, {}, {}, true, inputType ? {inputType, isComposing} : undefined);+ const shouldScroll = typewriterMode && !isComposing &&+ ["insertParagraph", "insertLineBreak"].includes(inputType);+ assert.deepEqual(events, ["input", "resume", ...(shouldScroll ? ["scroll"] : [])]);+ }+ }+ }+});diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 2dc6c5c8a9..0cad1280bc 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -1641,6 +1641,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const trackedRangeInsertion = prepareTrackedRangeInsertion(protyle, range);try {if (softEnter(range, nodeElement, protyle, trackedRangeInsertion)) {+ if (protyle.options.typewriterMode) {+ scheduleCaretScroll(protyle, "down");+ }event.stopPropagation();event.preventDefault();return;@@ -1682,6 +1685,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const trackedRangeInsertion = prepareTrackedRangeInsertion(protyle, range);try {await enter(nodeElement, range, protyle, trackedRangeInsertion);+ if (protyle.options.typewriterMode) {+ scheduleCaretScroll(protyle, "down");+ }} finally {endTrackedRangeInsertion(trackedRangeInsertion);}