inkmap-mcp 0.3.8 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,12 @@
1
1
  (function () {
2
- const isZh = () => /^zh\b/i.test(localStorage.getItem("inkmap.language") || navigator.language || "zh");
2
+ // The sidecar injects `data-os-locale` from the computer's OS timezone/language; UI language never decides it.
3
+ const osLocale = () => document.documentElement?.dataset?.osLocale || "";
4
+ const isZh = () => osLocale() ? osLocale() === "zh" : /^zh(?:[-_.]|$)/i.test(navigator.language || "");
3
5
  const text = (zh, en) => (isZh() ? zh : en);
4
6
 
5
- window.INKMAP_ASSET_BASE = "/api/doc-asset?path=";
6
- window.INKMAP_LOCALE = navigator.language;
7
+ // Each panel names itself, so the sidecar resolves this panel's images against the document it shows.
8
+ const panelId = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
9
+ window.INKMAP_ASSET_BASE = "/api/doc-asset?panel=" + encodeURIComponent(panelId) + "&path=";
7
10
  window.INKMAP_ACCOUNT_MODE = "restore";
8
11
 
9
12
  const params = new URLSearchParams(window.location.search);
@@ -20,8 +23,15 @@
20
23
  const apiFetch = async (path, options = {}) => {
21
24
  const fn = window.sidecar?.fetch ? window.sidecar.fetch.bind(window.sidecar) : window.fetch.bind(window);
22
25
  const method = (options.method || "GET").toUpperCase();
26
+ let body = options.body;
27
+ if (method !== "GET" && typeof body === "string") {
28
+ try {
29
+ body = JSON.stringify({ ...JSON.parse(body), panel: panelId });
30
+ } catch {}
31
+ }
23
32
  const res = await fn(path, {
24
33
  ...options,
34
+ body,
25
35
  method,
26
36
  headers: {
27
37
  "Content-Type": "application/json",
@@ -33,26 +43,6 @@
33
43
  return data;
34
44
  };
35
45
 
36
- const debugLog = (event, detail = {}) => {
37
- void apiFetch("/api/debug", {
38
- method: "POST",
39
- body: JSON.stringify({ event, ...detail, href: window.location.href, ts: Date.now() }),
40
- }).catch(() => {});
41
- };
42
-
43
- window.addEventListener("error", e => {
44
- debugLog("window.error", { message: e.message, filename: e.filename, lineno: e.lineno });
45
- });
46
- window.addEventListener("unhandledrejection", e => {
47
- debugLog("unhandledrejection", { reason: String(e.reason?.stack || e.reason) });
48
- });
49
- window.addEventListener("message", e => {
50
- if (e.data && typeof e.data === "object" && e.data.type === "__inkmap_debug") {
51
- debugLog(e.data.event || "client.debug", e.data);
52
- }
53
- });
54
- debugLog("bridge.loaded");
55
-
56
46
  const emitToEditor = msg => {
57
47
  window.postMessage(msg, "*");
58
48
  };
@@ -69,7 +59,6 @@
69
59
  return workspaceUris;
70
60
  }
71
61
 
72
- let fileSelectEl = null;
73
62
  let fileTriggerBtn = null;
74
63
  let fileTriggerNameEl = null;
75
64
  let fileTriggerDirEl = null;
@@ -93,6 +82,7 @@
93
82
  let mdEditTimer = 0;
94
83
  let activeStartLine = 0;
95
84
  let activeEndLine = 0;
85
+ let lastGutterKey = "";
96
86
 
97
87
  function parseFileEntry(item) {
98
88
  const label = typeof item.label === "string" ? item.label : "";
@@ -338,22 +328,30 @@
338
328
  }
339
329
  }
340
330
 
341
- function renderMdGutterAndBand() {
331
+ function renderMdGutterAndBand(scrollOnly = false) {
342
332
  if (!mdTextareaEl) return;
343
333
  const totalLines = Math.max(1, mdTextareaEl.value.split("\n").length);
344
334
  const sLine = Math.max(0, Math.min(activeStartLine, totalLines - 1));
345
335
  const eLine = Math.max(sLine, Math.min(activeEndLine, totalLines - 1));
346
- if (mdLineBadgeEl) {
347
- const label = sLine === eLine ? `${sLine + 1}` : `${sLine + 1}–${eLine + 1}`;
348
- mdLineBadgeEl.textContent = text(`行 ${label}`, `Ln ${label}`);
336
+ if (!scrollOnly) {
337
+ if (mdLineBadgeEl) {
338
+ const label = sLine === eLine ? `${sLine + 1}` : `${sLine + 1}–${eLine + 1}`;
339
+ mdLineBadgeEl.textContent = text(`行 ${label}`, `Ln ${label}`);
340
+ }
341
+ if (mdGutterEl) {
342
+ const key = `${totalLines}:${sLine}:${eLine}`;
343
+ if (key !== lastGutterKey) {
344
+ lastGutterKey = key;
345
+ const nums = [];
346
+ for (let i = 0; i < totalLines; i++) {
347
+ const active = i >= sLine && i <= eLine;
348
+ nums.push(`<div class="ag-gutter-ln${active ? " is-active" : ""}">${i + 1}</div>`);
349
+ }
350
+ mdGutterEl.innerHTML = nums.join("");
351
+ }
352
+ }
349
353
  }
350
354
  if (mdGutterEl) {
351
- const nums = [];
352
- for (let i = 0; i < totalLines; i++) {
353
- const active = i >= sLine && i <= eLine;
354
- nums.push(`<div class="ag-gutter-ln${active ? " is-active" : ""}">${i + 1}</div>`);
355
- }
356
- mdGutterEl.innerHTML = nums.join("");
357
355
  mdGutterEl.scrollTop = mdTextareaEl.scrollTop;
358
356
  }
359
357
  if (mdBandEl) {
@@ -374,7 +372,8 @@
374
372
  }
375
373
  if (!mdTextareaEl) return;
376
374
  if (force || document.activeElement !== mdTextareaEl) {
377
- if (mdTextareaEl.value !== md) mdTextareaEl.value = md;
375
+ const normalized = String(md || "").replace(/\r\n?/g, "\n");
376
+ if (mdTextareaEl.value !== normalized) mdTextareaEl.value = normalized;
378
377
  }
379
378
  renderMdGutterAndBand();
380
379
  }
@@ -411,17 +410,6 @@
411
410
 
412
411
  function renderFilePicker(files = [], selected = currentFile) {
413
412
  cachedFiles = Array.isArray(files) ? files : [];
414
- if (fileSelectEl) {
415
- fileSelectEl.innerHTML = "";
416
- for (const item of cachedFiles) {
417
- const opt = document.createElement("option");
418
- opt.value = item.path;
419
- opt.textContent = item.label;
420
- if (item.path === selected) opt.selected = true;
421
- fileSelectEl.appendChild(opt);
422
- }
423
- fileSelectEl.disabled = !cachedFiles.length;
424
- }
425
413
  if (openRawBtn) openRawBtn.disabled = !selected;
426
414
  if (fileTriggerBtn) {
427
415
  fileTriggerBtn.disabled = !cachedFiles.length;
@@ -447,9 +435,19 @@
447
435
  }
448
436
  }
449
437
 
438
+ async function flushPendingEdits() {
439
+ if (mdEditTimer) {
440
+ clearTimeout(mdEditTimer);
441
+ mdEditTimer = 0;
442
+ await window.inkmap?.load?.(currentMd, true);
443
+ }
444
+ await window.inkmap?.flushSave?.();
445
+ }
446
+
450
447
  async function switchFile(filePath) {
451
448
  if (!filePath || filePath === currentFile) return;
452
449
  try {
450
+ await flushPendingEdits();
453
451
  const data = await apiFetch("/api/open", {
454
452
  method: "POST",
455
453
  body: JSON.stringify({ workspaceUris, file: filePath }),
@@ -471,7 +469,7 @@
471
469
 
472
470
  function mountToolbarControls() {
473
471
  const bar = document.getElementById("bar");
474
- if (!bar || document.getElementById("ag-file-select")) return;
472
+ if (!bar || document.getElementById("ag-file-trigger")) return;
475
473
 
476
474
  const style = document.createElement("style");
477
475
  style.textContent = `
@@ -491,7 +489,6 @@
491
489
  width: calc(100vw - var(--ag-split-left, 42vw)) !important;
492
490
  height: calc(100vh - var(--toolbar-height, 44px)) !important;
493
491
  }
494
- #ag-file-select { display: none !important; }
495
492
  .ag-file-picker-wrap { position: relative; display: inline-flex; align-items: center; }
496
493
  #ag-file-trigger {
497
494
  display: inline-flex; align-items: center; gap: 5px; max-width: 210px; height: 28px;
@@ -680,13 +677,6 @@
680
677
  `;
681
678
  document.head.appendChild(style);
682
679
 
683
- fileSelectEl = document.createElement("select");
684
- fileSelectEl.id = "ag-file-select";
685
- fileSelectEl.hidden = true;
686
- fileSelectEl.addEventListener("change", () => {
687
- if (fileSelectEl.value) void switchFile(fileSelectEl.value);
688
- });
689
-
690
680
  const pickerWrap = document.createElement("div");
691
681
  pickerWrap.className = "ag-file-picker-wrap";
692
682
 
@@ -737,7 +727,7 @@
737
727
  }
738
728
  });
739
729
 
740
- pickerWrap.append(fileSelectEl, fileTriggerBtn);
730
+ pickerWrap.append(fileTriggerBtn);
741
731
 
742
732
  splitMdBtn = document.createElement("button");
743
733
  splitMdBtn.id = "ag-split-md";
@@ -812,7 +802,7 @@
812
802
  }
813
803
  if (mdTextareaEl) {
814
804
  mdTextareaEl.addEventListener("scroll", () => {
815
- renderMdGutterAndBand();
805
+ renderMdGutterAndBand(true);
816
806
  });
817
807
  const handleCursorMove = () => {
818
808
  if (!mdTextareaEl) return;
@@ -841,6 +831,8 @@
841
831
  renderMdGutterAndBand();
842
832
  clearTimeout(mdEditTimer);
843
833
  mdEditTimer = window.setTimeout(() => {
834
+ // The edit is being applied now; Cmd+S must not treat it as still pending.
835
+ mdEditTimer = 0;
844
836
  if (window.inkmap?.load) {
845
837
  void window.inkmap.load(nextMd, true).then(() => {
846
838
  emitToEditor({ type: "reveal", line: startLine });
@@ -849,14 +841,6 @@
849
841
  }, 320);
850
842
  });
851
843
  }
852
- document.querySelectorAll(".language-select").forEach(sel => {
853
- sel.addEventListener("change", () => {
854
- setTimeout(() => {
855
- applySplitLayout(false);
856
- renderFilePicker(cachedFiles, currentFile);
857
- }, 10);
858
- });
859
- });
860
844
  const resizer = document.getElementById("ag-md-resizer");
861
845
  if (resizer) {
862
846
  resizer.addEventListener("pointerdown", e => {
@@ -890,6 +874,45 @@
890
874
  let readyReceived = false;
891
875
  let initialDocSent = false;
892
876
  let lastLicense = { pro: false };
877
+ let magicPollInterval = 0;
878
+ let magicPollStop = 0;
879
+
880
+ async function refreshLicenseState() {
881
+ const state = await apiFetch("/api/license", { method: "GET" }).catch(() => null);
882
+ if (state) {
883
+ lastLicense = state;
884
+ emitToEditor({ type: "license", state });
885
+ }
886
+ return state;
887
+ }
888
+
889
+ function stopTemporaryLicensePoll() {
890
+ clearInterval(magicPollInterval);
891
+ clearTimeout(magicPollStop);
892
+ magicPollInterval = 0;
893
+ magicPollStop = 0;
894
+ }
895
+
896
+ /**
897
+ * Polls the license while the user finishes signing in or paying from the email. It runs until Pro is active, for
898
+ * as long as the sidecar checks the email's tokens quickly (30 minutes); a slower check covers later payments.
899
+ */
900
+ function startTemporaryLicensePoll(durationMs = 30 * 60_000) {
901
+ stopTemporaryLicensePoll();
902
+ magicPollInterval = window.setInterval(async () => {
903
+ const state = await refreshLicenseState();
904
+ if (state?.pro) stopTemporaryLicensePoll();
905
+ }, 2500);
906
+ magicPollStop = window.setTimeout(stopTemporaryLicensePoll, durationMs);
907
+ }
908
+
909
+ window.addEventListener("focus", () => {
910
+ if (initialDocSent) void refreshLicenseState();
911
+ });
912
+ // A payment made after the quick-poll window still unlocks the open panel.
913
+ setInterval(() => {
914
+ if (initialDocSent && !lastLicense?.pro && !magicPollInterval) void refreshLicenseState();
915
+ }, 20_000);
893
916
 
894
917
  function pushDocToEditor(doc, license = lastLicense) {
895
918
  if (!doc) return;
@@ -898,38 +921,13 @@
898
921
  if (!initialDocSent) {
899
922
  if (!readyReceived) return;
900
923
  initialDocSent = true;
901
- debugLog("emit.doc", { name: doc.name, mdLen: doc.md?.length });
902
924
  emitToEditor({
903
925
  type: "doc",
904
926
  doc,
905
927
  license: lastLicense || { pro: false },
906
- ads: [],
907
928
  chat: true,
908
929
  });
909
- setTimeout(() => {
910
- const mapEl = document.getElementById("map");
911
- debugLog("map.check.500ms", {
912
- hasInkmap: Boolean(window.inkmap),
913
- mapChildren: mapEl ? mapEl.children.length : -1,
914
- mapRect: mapEl ? mapEl.getBoundingClientRect() : null,
915
- innerW: window.innerWidth,
916
- innerH: window.innerHeight,
917
- bodyText: document.body?.innerText?.slice(0, 120),
918
- });
919
- }, 500);
920
- setTimeout(() => {
921
- const mapEl = document.getElementById("map");
922
- debugLog("map.check.2500ms", {
923
- hasInkmap: Boolean(window.inkmap),
924
- mapChildren: mapEl ? mapEl.children.length : -1,
925
- mapRect: mapEl ? mapEl.getBoundingClientRect() : null,
926
- innerW: window.innerWidth,
927
- innerH: window.innerHeight,
928
- bodyText: document.body?.innerText?.slice(0, 120),
929
- });
930
- }, 2500);
931
930
  } else {
932
- debugLog("emit.change", { name: doc.name, mdLen: doc.md?.length });
933
931
  emitToEditor({ type: "change", doc });
934
932
  }
935
933
  }
@@ -937,7 +935,6 @@
937
935
  if (window.sidecar?.onWorkspaceChange) {
938
936
  window.sidecar.onWorkspaceChange(async nextUris => {
939
937
  workspaceUris = Array.isArray(nextUris) ? nextUris : [];
940
- debugLog("workspace.change", { workspaceUris });
941
938
  try {
942
939
  const data = await apiFetch("/api/init", {
943
940
  method: "POST",
@@ -953,26 +950,32 @@
953
950
  currentMd = data.doc.md;
954
951
  pushDocToEditor(data.doc, data.license);
955
952
  }
956
- } catch (err) {
957
- debugLog("workspace.change.err", { error: String(err) });
958
- }
953
+ } catch {}
959
954
  });
960
955
  }
961
956
 
962
- // Poll for external file edits or AI skill file switches (`select.mjs`).
957
+ // Poll for external file edits or AI tool file switches.
958
+ let polling = false;
963
959
  setInterval(async () => {
964
- if (!initialDocSent || saving) return;
960
+ if (!initialDocSent || saving || polling) return;
961
+ polling = true;
962
+ const polledFile = currentFile;
963
+ const polledVersion = currentVersion;
965
964
  try {
966
965
  const res = await apiFetch("/api/poll", {
967
966
  method: "POST",
968
967
  body: JSON.stringify({
969
- ...(currentFile && { file: currentFile }),
970
- ...(currentVersion && { version: currentVersion }),
968
+ ...(polledFile && { file: polledFile }),
969
+ ...(polledVersion && { version: polledVersion }),
971
970
  targetSeq: String(targetSeq),
971
+ workspaceUris,
972
972
  }),
973
973
  });
974
974
  if (res.targetSeq) targetSeq = res.targetSeq;
975
+ if (saving) return;
975
976
  if (res.switchedFile && res.doc) {
977
+ clearTimeout(mdEditTimer);
978
+ mdEditTimer = 0;
976
979
  currentFile = res.switchedFile;
977
980
  currentFileUri = res.currentFileUri;
978
981
  currentVersion = res.doc.version;
@@ -986,26 +989,28 @@
986
989
  setTimeout(() => {
987
990
  try { window.inkmap?.mindMap?.view?.fit(); } catch {}
988
991
  }, 120);
989
- } else if (res.changed && res.doc) {
992
+ } else if (res.changed && res.doc && currentFile === polledFile && currentVersion === polledVersion) {
993
+ if (res.doc.version === currentVersion) return;
990
994
  currentVersion = res.doc.version;
991
995
  currentMd = res.doc.md;
992
996
  pushDocToEditor(res.doc);
993
997
  }
994
- } catch {}
998
+ } catch {} finally {
999
+ polling = false;
1000
+ }
995
1001
  }, 1200);
996
1002
 
997
1003
  function sliceLines(md, startLine, endLine, subText) {
998
1004
  if (subText) return subText;
999
- const lines = String(md || "").split("\n");
1000
- const s = Math.max(0, Math.min(startLine ?? 0, lines.length - 1));
1001
- const e = Math.max(s, Math.min(endLine ?? s, lines.length - 1));
1005
+ const lines = String(md || "").replace(/\r\n?/g, "\n").split("\n");
1006
+ const s = Math.max(0, Math.min(startLine ?? 0, Math.max(0, lines.length - 1)));
1007
+ const e = Math.max(s, Math.min(endLine ?? s, Math.max(0, lines.length - 1)));
1002
1008
  return lines.slice(s, e + 1).join("\n");
1003
1009
  }
1004
1010
 
1005
1011
  window.acquireVsCodeApi = () => ({
1006
1012
  async postMessage(msg) {
1007
1013
  if (!msg || typeof msg !== "object") return;
1008
- debugLog("postMessage", { type: msg.type });
1009
1014
  try {
1010
1015
  switch (msg.type) {
1011
1016
  case "ready": {
@@ -1086,15 +1091,15 @@
1086
1091
  const lineHeight = 20.8;
1087
1092
  const padTop = 12;
1088
1093
  const target = Math.max(0, padTop + sLine * lineHeight - mdTextareaEl.clientHeight * 0.35);
1089
- try { mdTextareaEl.setSelectionRange(startOffset, Math.max(startOffset, endOffset)); } catch {}
1094
+ if (document.activeElement === mdTextareaEl) {
1095
+ try { mdTextareaEl.setSelectionRange(startOffset, Math.max(startOffset, endOffset)); } catch {}
1096
+ }
1090
1097
  mdTextareaEl.scrollTop = target;
1098
+ mdTextareaEl.scrollLeft = 0;
1091
1099
  requestAnimationFrame(() => {
1092
1100
  if (!mdTextareaEl?.isConnected) return;
1093
- try {
1094
- mdTextareaEl.focus({ preventScroll: true });
1095
- mdTextareaEl.setSelectionRange(startOffset, Math.max(startOffset, endOffset));
1096
- } catch {}
1097
1101
  mdTextareaEl.scrollTop = target;
1102
+ mdTextareaEl.scrollLeft = 0;
1098
1103
  });
1099
1104
  renderMdGutterAndBand();
1100
1105
  }
@@ -1108,61 +1113,76 @@
1108
1113
  window.inkmap?.mindMap?.execCommand("FORWARD");
1109
1114
  return;
1110
1115
  }
1116
+ case "openInBrowser": {
1117
+ await apiFetch("/api/open-browser", {
1118
+ method: "POST",
1119
+ body: JSON.stringify({ file: currentFile, workspaceUris }),
1120
+ });
1121
+ return;
1122
+ }
1111
1123
  case "addToChat": {
1112
1124
  if (!currentFile) return;
1113
- const snippet = sliceLines(currentMd, msg.startLine, msg.endLine, msg.text);
1125
+ const hasRange = msg.startLine !== undefined;
1126
+ const sOne = (msg.startLine ?? 0) + 1;
1127
+ const eOne = (msg.endLine ?? msg.startLine ?? 0) + 1;
1128
+ const snippet = hasRange ? sliceLines(currentMd, msg.startLine, msg.endLine, msg.text) : "";
1114
1129
  if (window.sidecar?.ui?.addArtifactComment && currentFileUri) {
1115
1130
  window.sidecar.ui.addArtifactComment({
1116
1131
  uri: currentFileUri,
1117
- comment: snippet,
1118
- selection: {
1119
- startLine: (msg.startLine ?? 0) + 1,
1120
- endLine: (msg.endLine ?? msg.startLine ?? 0) + 1,
1121
- },
1132
+ comment: hasRange ? snippet : text(`请结合 ${currentFile} 进行分析`, `Analyze ${currentFile}`),
1133
+ ...(hasRange && {
1134
+ selection: {
1135
+ startLine: sOne,
1136
+ endLine: eOne,
1137
+ },
1138
+ }),
1122
1139
  pageTitle: currentFile.split(/[\\/]/).pop() || "Inkmap",
1123
1140
  });
1124
1141
  } else if (window.sidecar?.agent?.sendMessage && window.sidecar.conversationId) {
1125
- await window.sidecar.agent.sendMessage(
1126
- `来自 \`${currentFile}\`(第 ${(msg.startLine ?? 0) + 1}–${(msg.endLine ?? 0) + 1} 行):\n\`\`\`markdown\n${snippet}\n\`\`\``,
1127
- window.sidecar.conversationId,
1128
- );
1142
+ const prompt = hasRange
1143
+ ? text(`来自 \`${currentFile}\`(第 ${sOne}–${eOne} 行):`, `From \`${currentFile}\` (lines ${sOne}–${eOne}):`) +
1144
+ `\n\`\`\`markdown\n${snippet}\n\`\`\``
1145
+ : text(`请结合思维导图文件 \`${currentFile}\` 进行分析。`, `Please use the mind map file \`${currentFile}\` as context.`);
1146
+ await window.sidecar.agent.sendMessage(prompt, window.sidecar.conversationId);
1129
1147
  }
1130
1148
  return;
1131
1149
  }
1132
1150
  case "checkout": {
1151
+ const locale = osLocale() || undefined;
1133
1152
  const res = await apiFetch("/api/checkout", {
1134
1153
  method: "POST",
1135
- body: JSON.stringify({ mode: "restore" }),
1154
+ body: JSON.stringify({ mode: "restore", locale }),
1136
1155
  });
1137
1156
  emitToEditor({ type: "checkout", id: msg.id });
1138
- // Poll license state after restore sign-in link opens
1139
- const checkTimer = setInterval(async () => {
1140
- const state = await apiFetch("/api/license", { method: "GET" }).catch(() => null);
1141
- if (state) emitToEditor({ type: "license", state });
1142
- if (state?.pro || state?.connected) clearInterval(checkTimer);
1143
- }, 3000);
1144
- setTimeout(() => clearInterval(checkTimer), 120_000);
1157
+ startTemporaryLicensePoll();
1145
1158
  if (res.url && !window.sidecar) window.open(res.url, "_blank", "noopener,noreferrer");
1146
1159
  return;
1147
1160
  }
1148
1161
  case "sendPhoneCode": {
1162
+ const locale = osLocale() || undefined;
1149
1163
  const { result } = await apiFetch("/api/phone-send", {
1150
1164
  method: "POST",
1151
- body: JSON.stringify({ phone: msg.phone }),
1165
+ body: JSON.stringify({ phone: msg.phone, locale }),
1152
1166
  });
1153
1167
  emitToEditor({ type: "phoneCodeSent", id: msg.id, result });
1168
+ if (result?.ok) startTemporaryLicensePoll();
1154
1169
  return;
1155
1170
  }
1156
1171
  case "signInByPhone": {
1172
+ const locale = osLocale() || undefined;
1157
1173
  const { result } = await apiFetch("/api/phone-verify", {
1158
1174
  method: "POST",
1159
- body: JSON.stringify({ phone: msg.phone, code: msg.code }),
1175
+ body: JSON.stringify({ phone: msg.phone, code: msg.code, locale }),
1160
1176
  });
1177
+ if (result?.ok && result.value) lastLicense = result.value;
1161
1178
  emitToEditor({ type: "phoneSignIn", id: msg.id, result });
1179
+ // A verified email without Pro waits for payment in the sidecar; watch for it here too.
1180
+ if (!result?.value?.pro) startTemporaryLicensePoll();
1162
1181
  return;
1163
1182
  }
1164
1183
  case "signOut": {
1165
1184
  const { state } = await apiFetch("/api/signout", { method: "POST", body: "{}" });
1185
+ if (state) lastLicense = state;
1166
1186
  emitToEditor({ type: "signedOut", id: msg.id });
1167
1187
  if (state) emitToEditor({ type: "license", state });
1168
1188
  return;
@@ -1184,7 +1204,6 @@
1184
1204
  }
1185
1205
  }
1186
1206
  } catch (err) {
1187
- debugLog("postMessage.error", { type: msg.type, error: String(err?.stack || err) });
1188
1207
  if ("id" in msg) {
1189
1208
  emitToEditor({
1190
1209
  type: "error",
@@ -1196,8 +1215,15 @@
1196
1215
  },
1197
1216
  });
1198
1217
 
1199
- // Restore keyboard undo/redo since VsCodeHost removes simple-mind-map's default Control+z / Control+y
1218
+ // Restore keyboard undo/redo and flush split-pane edits on Cmd+S
1200
1219
  window.addEventListener("keydown", e => {
1220
+ if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey && e.key.toLowerCase() === "s") {
1221
+ if (mdEditTimer) {
1222
+ e.preventDefault();
1223
+ void flushPendingEdits();
1224
+ return;
1225
+ }
1226
+ }
1201
1227
  if (e.defaultPrevented || e.isComposing) return;
1202
1228
  const tag = (e.target?.tagName || "").toUpperCase();
1203
1229
  if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || e.target?.isContentEditable) return;