mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-11-27 06:32:42 +00:00
Implement the scoped fixes for PR #3046: - Ignore unsupported aliases while retaining whole string/list aliases and paths. - Use Obsidian source-heading identities for section targets, preserving legacy image-transclusion matching. - Block Ctrl/Cmd+Shift+S only in the focused drawing editor, retaining normal save and explicit legacy export. - Honor internal-link removal in manual vault and clipboard SVG exports through the existing scene filter without mutating source elements or changing hooks. Add source and native regressions, including standalone H2 wikilinks, aliased and unresolved wikilinks, save/reopen, image decoding and ordinary section-link navigation in Reading and Live Preview. Preserve the original NBSP attachment with provenance. Add the requested CLI troubleshooting guidance and remove the temporary plan-only handoff. Validation: 993 portable cases passed; 776 fast/source tests passed; all ten PR-specific native cases passed in main and popout, including the expanded wikilink matrix. Production build and all five bundle tests passed. No new lint diagnostics; the repository retains 116 existing errors. The exact tested build was deployed to Zsolt's Brain with backed-up artifacts and unchanged settings. The complete native profile remains failed: table controls also fail on the unchanged baseline; the offscreen phone toolbar remains unclassified against baseline. Initial zoom-settling and popout code-image reopen failures passed focused reruns. macOS, physical mobile and minimum-version Obsidian remain untested. Original SVG escaping (#2570) and NBSP (#2389) reports did not reproduce on this Windows host; they gain coverage without speculative serializer/cache changes. Optional simple-columns compatibility (#2858) is deferred.
72 lines
4.0 KiB
JavaScript
72 lines
4.0 KiB
JavaScript
/** Execute the production capture handler, including retirement during submission. */
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { sourceHarness } from "./sourceHarness.mjs";
|
|
|
|
const harness = sourceHarness();
|
|
const { handleTextSaveShortcut, handleSaveAsShortcut } = await harness.importModule("src/view/managers/textSaveShortcut.ts");
|
|
test.after(() => harness.close());
|
|
|
|
function fixture() {
|
|
const calls = [], doc = {}, api = {}, file = {};
|
|
const editable = { tagName: "TEXTAREA", classList: { contains: name => name === "excalidraw-wysiwyg" }, ownerDocument: doc,
|
|
blur() { calls.push("submit"); } };
|
|
doc.activeElement = editable;
|
|
const view = { excalidrawAPI: api, file, ownerDocument: doc, containerEl: { contains: () => true },
|
|
isClosingOrMigrating: () => false,
|
|
packages: { reactDOM: { flushSync(callback) { calls.push("flush"); callback(); calls.push("committed"); } } },
|
|
forceSave(...args) { calls.push(["forceSave", ...args]); } };
|
|
const event = { target: editable, key: "s", ctrlKey: true,
|
|
preventDefault() { calls.push("preventDefault"); }, stopPropagation() { calls.push("stopPropagation"); } };
|
|
return { calls, doc, editable, view, event };
|
|
}
|
|
|
|
for (const modifier of ["ctrlKey", "metaKey"]) {
|
|
test(`${modifier} save submits and commits before forced persistence, waiting for busy saves`, () => {
|
|
const f = fixture(); Object.assign(f.event, { ctrlKey: false, [modifier]: true, key: "S" });
|
|
handleTextSaveShortcut(f.view, f.event);
|
|
assert.deepEqual(f.calls, ["preventDefault", "stopPropagation", "flush", "submit", "committed", ["forceSave", false, true]]);
|
|
});
|
|
}
|
|
test("unrelated shortcuts, Shift+S and embedded Markdown editors retain their handlers", () => {
|
|
for (const mutation of [
|
|
f => f.event.shiftKey = true, f => f.event.altKey = true, f => f.event.ctrlKey = false,
|
|
f => f.event.key = "x", f => f.editable.tagName = "DIV", f => f.editable.classList.contains = () => false,
|
|
f => f.doc.activeElement = {}, f => f.view.containerEl.contains = () => false, f => f.editable.ownerDocument = {},
|
|
f => f.view.file = null, f => f.view.excalidrawAPI = null, f => f.view.isClosingOrMigrating = () => true,
|
|
]) {
|
|
const f = fixture(); mutation(f); handleTextSaveShortcut(f.view, f.event); assert.deepEqual(f.calls, []);
|
|
}
|
|
});
|
|
test("submission cannot save a replacement file, API or retiring view", () => {
|
|
for (const retire of [f => f.view.file = {}, f => f.view.excalidrawAPI = {}, f => f.view.isClosingOrMigrating = () => true]) {
|
|
const f = fixture(); f.editable.blur = () => { f.calls.push("submit"); retire(f); };
|
|
handleTextSaveShortcut(f.view, f.event);
|
|
assert.deepEqual(f.calls, ["preventDefault", "stopPropagation", "flush", "submit", "committed"]);
|
|
}
|
|
});
|
|
|
|
test("focused canvas and text editor block Ctrl/Cmd+Shift+S without submitting or saving", () => {
|
|
for (const modifier of ["ctrlKey", "metaKey"]) for (const tagName of ["DIV", "TEXTAREA"]) {
|
|
const f = fixture(); f.editable.tagName = tagName; f.editable.closest = () => null;
|
|
Object.assign(f.event, { ctrlKey: false, [modifier]: true, shiftKey: true, key: "S" });
|
|
assert.equal(handleSaveAsShortcut(f.view, f.event), true);
|
|
assert.deepEqual(f.calls, ["preventDefault", "stopPropagation"]);
|
|
}
|
|
});
|
|
|
|
test("Save As guard leaves other shortcuts, other documents, unfocused views and embedded notes alone", () => {
|
|
for (const mutate of [
|
|
f => f.event.shiftKey = false, f => f.event.altKey = true,
|
|
f => f.event.ctrlKey = false, f => f.event.key = "x",
|
|
f => f.editable.ownerDocument = {}, f => f.doc.activeElement = {},
|
|
f => f.view.containerEl.contains = () => false,
|
|
f => f.editable.closest = selector => selector === ".excalidraw__embeddable-container" ? {} : null,
|
|
f => f.view.file = null, f => f.view.excalidrawAPI = null,
|
|
f => f.view.isClosingOrMigrating = () => true,
|
|
]) {
|
|
const f = fixture(); f.event.shiftKey = true; f.editable.closest = () => null; mutate(f);
|
|
assert.equal(handleSaveAsShortcut(f.view, f.event), false); assert.deepEqual(f.calls, []);
|
|
}
|
|
});
|