mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-11-27 06:32:42 +00:00
Preserve editor focus when constructing internal Markdown previews
This commit is contained in:
1 parent
8c9a9460f1
commit
38bf80fbf4
8 files changed
+203
-11
No files matched your search
@@ -3136,3 +3136,12 @@ remain strict pending maintainer classification; no production changes.
|
||||
accepted scope. Full native CLI accounting is six cases including Lucide;
|
||||
phone/tablet EA protocol cases remain separate. Highest-risk next checks are
|
||||
mobile embedded-note focus and fresh complete matrix/cleanup repeats.
|
||||
|
||||
- 2026-10-29 (#3022): Implemented the explicitly approved internal Canvas-node
|
||||
`focus: false` correction. Four actual-method regressions pass, including the
|
||||
old-path negative control and preservation of explicit editing activation.
|
||||
Retained all `patchMobileView` visibility handling. The exact production-diff
|
||||
audit now permits only this additional flag/type and release note. Highest-risk
|
||||
validation is phone/tablet embedded Markdown loading and deliberate editing;
|
||||
desktop/popout embedding remains in the complete native repeats. Physical mobile
|
||||
touch behavior remains a separate validation environment.
|
||||
+2
-2
@@ -10,8 +10,8 @@ all **15 popout drop variants**, cleanup and baseline restoration; the core run
|
||||
records zero unexpected errors/notifications. Native error/layout negative controls
|
||||
pass. Real single-export PDF output is decoded and visually inspected.
|
||||
|
||||
Acceptance remains **incomplete**: an isolated mobile embedding exception needs a
|
||||
production decision (F17), and **zero of two required complete native repeats**
|
||||
Acceptance remains **incomplete**: the approved mobile embedding focus correction
|
||||
(F17) needs fresh native confirmation, and **zero of two required complete native repeats**
|
||||
have passed. Do not merge or substitute these subset results for the 357-case gate.
|
||||
The full plan has six native CLI-bearing cases (five editing plus Lucide) and two
|
||||
separate mobile public `EA.executeCLI` workflows. Historical checkpoints below
|
||||
|
||||
@@ -230,7 +230,7 @@ fail the inherited notification storm and the two feature-bearing profiles also
|
||||
reflect their workflow failures. Cleanup and baseline restoration pass. Neither
|
||||
required full repeat has passed yet.
|
||||
|
||||
## F17 - Mobile embedding exception: production approval pending
|
||||
## F17 - Mobile embedding exception: approved focus correction
|
||||
|
||||
The isolated command below reproduces the exception with only the embedding
|
||||
workflow selected; its rendering/save/reopen assertions pass but the JavaScript
|
||||
@@ -245,10 +245,15 @@ node scripts/testing/host/verify.mjs --profile=devices --device-profiles=phone-p
|
||||
embedded Markdown preview with no editor. The active drawing remains Excalidraw.
|
||||
Inspection of Obsidian 1.14.5's actual `createFileNode` implementation confirms
|
||||
that omitted `focus` defaults to selection/focus of the new node. The plugin's
|
||||
internal Canvas-node factory currently omits that option. Proposed narrow fix:
|
||||
create this internal node with `focus: false`, preserving deliberate editing
|
||||
activation. The maintainer has been asked for explicit approval. No production
|
||||
change or exception filtering has been made for this finding.
|
||||
internal Canvas-node factory omitted that option. The maintainer explicitly
|
||||
approved the narrow fix: create this internal node with `focus: false`, preserving
|
||||
deliberate editing activation. This correction is now implemented, with four
|
||||
actual-method regressions covering construction, replacement, explicit editing
|
||||
and a negative control reproducing the old missing-editor failure. All four pass.
|
||||
The existing `patchMobileView` visibility workaround remains unchanged: preventing
|
||||
unrequested editor activation does not establish that mobile visibility patching
|
||||
can be removed. Fresh native confirmation and complete repeats remain required;
|
||||
the exception gate has not been weakened.
|
||||
|
||||
The next independent-core run retains failures from cleaned scenarios instead of
|
||||
omitting later unrelated cases. Pending native work still stops the sequence.
|
||||
@@ -279,7 +284,7 @@ verification passes 650 canonical cases (52 new, 598 reused), plus source/packag
|
||||
gates. [Sanitized, accessible evidence](testing-evidence/3022/README.md) records
|
||||
case results and actual source/artifact hashes.
|
||||
|
||||
This does not establish full acceptance: F17 production approval is pending and
|
||||
neither complete matching-build repeat has passed. CLI accounting includes the
|
||||
This does not establish full acceptance: the approved F17 correction still needs
|
||||
fresh native confirmation and neither complete matching-build repeat has passed. CLI accounting includes the
|
||||
Lucide case's real native commands: six CLI-bearing cases in the full plan, with
|
||||
the two mobile public EA protocol cases reported separately.
|
||||
@@ -0,0 +1,157 @@
|
||||
/** Execute actual factory methods with a deterministic Obsidian focus boundary.
|
||||
* AST isolation receives no whole-module coverage or native-rendering credit.
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { readFileSync } from "node:fs";
|
||||
import vm from "node:vm";
|
||||
import ts from "typescript";
|
||||
|
||||
function factory({ originalFocus = false } = {}) {
|
||||
const source = readFileSync(
|
||||
new URL("../../src/view/managers/CanvasNodeFactory.ts", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
const tree = ts.createSourceFile(
|
||||
"CanvasNodeFactory.ts",
|
||||
source,
|
||||
ts.ScriptTarget.Latest,
|
||||
true,
|
||||
),
|
||||
methods = [];
|
||||
const visit = (node) => {
|
||||
if (
|
||||
ts.isMethodDeclaration(node) &&
|
||||
["createFileNote", "startEditing"].includes(node.name.getText(tree))
|
||||
)
|
||||
methods.push(node.getText(tree));
|
||||
ts.forEachChild(node, visit);
|
||||
};
|
||||
visit(tree);
|
||||
assert.equal(methods.length, 2);
|
||||
let code = methods.join("\n");
|
||||
if (originalFocus) code = code.replace(/\s*focus: false,/, "");
|
||||
const exports = {},
|
||||
errors = [];
|
||||
vm.runInNewContext(
|
||||
ts.transpileModule("export class Subject{" + code + "}", {
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
},
|
||||
}).outputText,
|
||||
{
|
||||
exports,
|
||||
isObsidianThemeDark: () => false,
|
||||
console: { error: (...args) => errors.push(args) },
|
||||
},
|
||||
);
|
||||
const previous = { editor: { hasFocus: () => true } },
|
||||
state = {
|
||||
activeEditor: previous,
|
||||
previous,
|
||||
removed: [],
|
||||
appended: [],
|
||||
editRequests: [],
|
||||
errors,
|
||||
blockersRemoved: 0,
|
||||
};
|
||||
const subject = Object.assign(new exports.Subject(), {
|
||||
initialized: true,
|
||||
nodes: new Map(),
|
||||
pendingEditRequests: new WeakMap(),
|
||||
view: {
|
||||
async setEmbeddableNodeIsEditing(id) {
|
||||
state.editRequests.push(id);
|
||||
},
|
||||
},
|
||||
canvas: {
|
||||
createFileNode(options) {
|
||||
const node = {
|
||||
options,
|
||||
child: { file: options.file },
|
||||
isEditable: () => true,
|
||||
setFilePath(path, subpath) {
|
||||
this.path = path;
|
||||
this.subpath = subpath;
|
||||
},
|
||||
render() {
|
||||
this.rendered = true;
|
||||
},
|
||||
containerEl: {
|
||||
querySelector: () => ({
|
||||
remove() {
|
||||
state.blockersRemoved++;
|
||||
},
|
||||
}),
|
||||
},
|
||||
startEditing() {
|
||||
this.child.editor = { hasFocus: () => true };
|
||||
state.activeEditor = this.child;
|
||||
},
|
||||
};
|
||||
// Obsidian's real createFileNode defaults omitted focus to selectOnly(node).
|
||||
if (options.focus !== false) state.activeEditor = node.child;
|
||||
return node;
|
||||
},
|
||||
removeNode(node) {
|
||||
state.removed.push(node);
|
||||
},
|
||||
},
|
||||
});
|
||||
state.subject = subject;
|
||||
state.file = { path: "Notes/Owned.md" };
|
||||
state.container = {
|
||||
appendChild(node) {
|
||||
state.appended.push(node);
|
||||
},
|
||||
};
|
||||
return state;
|
||||
}
|
||||
|
||||
test("internal preview construction preserves the active editor and renders the requested file", () => {
|
||||
const s = factory(),
|
||||
node = s.subject.createFileNote(s.file, "#Heading", s.container, "owned");
|
||||
assert.equal(s.activeEditor, s.previous);
|
||||
assert.equal(s.activeEditor.editor.hasFocus(), true);
|
||||
assert.equal(node.path, s.file.path);
|
||||
assert.equal(node.subpath, "#Heading");
|
||||
assert.equal(node.rendered, true);
|
||||
assert.equal(s.subject.nodes.get("owned"), node);
|
||||
assert.deepEqual(s.appended, [node.containerEl]);
|
||||
assert.equal(s.blockersRemoved, 1);
|
||||
});
|
||||
|
||||
test("replacing an internal preview preserves focus and replaces only its registered node", () => {
|
||||
const s = factory(),
|
||||
first = s.subject.createFileNote(s.file, null, s.container, "owned");
|
||||
const second = s.subject.createFileNote(
|
||||
s.file,
|
||||
"#Next",
|
||||
s.container,
|
||||
"owned",
|
||||
);
|
||||
assert.equal(first.subpath, "");
|
||||
assert.deepEqual(s.removed, [first]);
|
||||
assert.equal(s.subject.nodes.get("owned"), second);
|
||||
assert.equal(s.activeEditor, s.previous);
|
||||
});
|
||||
|
||||
test("explicit embedded-note editing still enters the editor and acquires focus", async () => {
|
||||
const s = factory(),
|
||||
node = s.subject.createFileNote(s.file, "", s.container, "owned");
|
||||
assert.equal(s.activeEditor, s.previous);
|
||||
await s.subject.startEditing(node, "theme-light", true, "owned");
|
||||
assert.equal(node.isEditing, true);
|
||||
assert.equal(s.activeEditor, node.child);
|
||||
assert.equal(s.activeEditor.editor.hasFocus(), true);
|
||||
assert.deepEqual(s.editRequests, ["owned"]);
|
||||
assert.deepEqual(s.errors, []);
|
||||
});
|
||||
|
||||
test("the old default-focus path reproduces the missing-editor toolbar failure", () => {
|
||||
const s = factory({ originalFocus: true });
|
||||
s.subject.createFileNote(s.file, "", s.container, "owned");
|
||||
assert.notEqual(s.activeEditor, s.previous);
|
||||
assert.throws(() => s.activeEditor.editor.hasFocus(), /hasFocus/);
|
||||
});
|
||||
@@ -18,7 +18,7 @@ export function reviewProductionDiff({
|
||||
const roots = { plugin: pluginRoot, fork: forkRoot, extras: extrasRoot },
|
||||
report = {
|
||||
scope:
|
||||
"PDF timeout/concurrency rollback, plus the maintainer-authorized plain-PDF and local-font fixes of 2026-10-29 and their release notes; no other production changes.",
|
||||
"PDF timeout/concurrency rollback, plus the maintainer-authorized plain-PDF, local-font and internal Canvas-node focus fixes of 2026-10-29 and their release notes; no other production changes.",
|
||||
baselines,
|
||||
repositories: {},
|
||||
};
|
||||
@@ -67,6 +67,7 @@ export function reviewProductionDiff({
|
||||
? [
|
||||
"src/shared/Dialogs/Messages.ts",
|
||||
"src/shared/EmbeddedFileLoader.ts",
|
||||
"src/view/managers/CanvasNodeFactory.ts",
|
||||
]
|
||||
: ["packages/excalidraw/obsidianUtils.ts"],
|
||||
kind + " has an unauthorized additional production diff",
|
||||
@@ -87,6 +88,17 @@ export function reviewProductionDiff({
|
||||
);
|
||||
};
|
||||
if (kind === "plugin") {
|
||||
expectedFile("src/view/managers/CanvasNodeFactory.ts", (source) =>
|
||||
source
|
||||
.replace(
|
||||
" save: boolean;",
|
||||
" save: boolean;\n focus: boolean;",
|
||||
)
|
||||
.replace(
|
||||
" save: false,",
|
||||
" save: false,\n // Internal preview creation must not take the workspace's active editor.\n focus: false,",
|
||||
),
|
||||
);
|
||||
expectedFile("src/shared/EmbeddedFileLoader.ts", (source) =>
|
||||
source.replace(
|
||||
'linkParts.ref\n .split("rect=")[1]',
|
||||
@@ -98,6 +110,7 @@ export function reviewProductionDiff({
|
||||
"## Fixed\n- Autosave",
|
||||
[
|
||||
"## Fixed",
|
||||
"- Embedded Markdown previews no longer take editor focus when they load, avoiding a mobile toolbar error. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)",
|
||||
"- Importing a PDF file through ExcalidrawAutomate loads page 1 when no page reference is supplied. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)",
|
||||
"- Markdown images using Helvetica no longer try to fetch a nonexistent font file. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)",
|
||||
"- Autosave",
|
||||
@@ -206,7 +219,7 @@ if (
|
||||
JSON.stringify(report, null, 2) + "\n",
|
||||
);
|
||||
process.stdout.write(
|
||||
"Production diff audit passed: exact plain-PDF/local-font fixes and release notes; Extras PDF rollback only. " +
|
||||
"Production diff audit passed: exact plain-PDF/local-font/internal-node-focus fixes and release notes; Extras PDF rollback only. " +
|
||||
output +
|
||||
"\n",
|
||||
);
|
||||
|
||||
@@ -30,6 +30,7 @@ I build this plugin as a labor of love. Curious about the philosophy behind it?
|
||||
- Added opt-in image inventory, bounded image labels/tags, mixed-fidelity SVG/PNG previews and output limits. Originals remain untouched and full fidelity stays the default. [#3004](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/3004)
|
||||
|
||||
## Fixed
|
||||
- Embedded Markdown previews no longer take editor focus when they load, avoiding a mobile toolbar error. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)
|
||||
- Importing a PDF file through ExcalidrawAutomate loads page 1 when no page reference is supplied. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)
|
||||
- Markdown images using Helvetica no longer try to fetch a nonexistent font file. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)
|
||||
- Autosave recovers after an unexpected save error instead of remaining busy. [#3022](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_PULL}/3022)
|
||||
|
||||
@@ -32,6 +32,7 @@ interface ObsidianCanvas {
|
||||
file: TFile;
|
||||
subpath: string;
|
||||
save: boolean;
|
||||
focus: boolean;
|
||||
}) => ObsidianCanvasNode;
|
||||
removeNode: (node: ObsidianCanvasNode) => void;
|
||||
}
|
||||
@@ -148,6 +149,8 @@ export class CanvasNodeFactory {
|
||||
file,
|
||||
subpath,
|
||||
save: false,
|
||||
// Internal preview creation must not take the workspace's active editor.
|
||||
focus: false,
|
||||
});
|
||||
node.setFilePath(file.path, subpath);
|
||||
node.render();
|
||||
|
||||
@@ -2401,6 +2401,10 @@
|
||||
"path": "scripts/testing/bundle.test.mjs",
|
||||
"mode": "isolated-or-extracted"
|
||||
},
|
||||
{
|
||||
"path": "scripts/testing/canvasNodeFocus.test.mjs",
|
||||
"mode": "isolated-or-extracted"
|
||||
},
|
||||
{
|
||||
"path": "scripts/testing/cli.test.mjs",
|
||||
"mode": "isolated-or-extracted"
|
||||
|
||||
Reference in new issue
Block a user