Skip to content

Commit e735611

Browse files
committed
fix(mdviewer): global edit mode across file switches and underline shortcut tooltip
Edit mode is now preserved globally when switching files instead of per-document. Added ({mod}+U) shortcut to underline tooltip string.
1 parent 652ec60 commit e735611

2 files changed

Lines changed: 15 additions & 28 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,17 @@ function handleSwitchFile(data) {
309309

310310
_suppressContentChange = true;
311311

312+
// Edit mode is global for the md editor frame — preserve it across file switches
313+
const wasEditMode = getState().editMode;
314+
312315
// Save state for outgoing document
313316
const outgoingPath = docCache.getActiveFilePath();
314317
if (outgoingPath) {
315318
docCache.saveActiveScrollPos();
316-
// Save edit mode state in cache entry
317-
const outEntry = docCache.getEntry(outgoingPath);
318-
if (outEntry) {
319-
outEntry._editMode = getState().editMode;
320-
}
321319
}
322320

323-
// Exit edit mode before switching DOM if currently editing
324-
if (getState().editMode) {
321+
// Exit edit mode before switching DOM to detach handlers from outgoing element
322+
if (wasEditMode) {
325323
emit("doc:beforeSwitch", { fromPath: outgoingPath, toPath: filePath });
326324
setState({ editMode: false });
327325
}
@@ -337,11 +335,6 @@ function handleSwitchFile(data) {
337335
parseResult: existing.parseResult
338336
});
339337

340-
// Restore edit mode for this document
341-
if (existing._editMode) {
342-
setState({ editMode: true });
343-
}
344-
345338
emit("file:switched", { filePath });
346339
} else if (existing) {
347340
// Cache hit, content changed — re-render in place
@@ -354,11 +347,6 @@ function handleSwitchFile(data) {
354347
parseResult: parseResult
355348
});
356349

357-
// Restore edit mode for this document
358-
if (existing._editMode) {
359-
setState({ editMode: true });
360-
}
361-
362350
emit("file:rendered", parseResult);
363351
} else {
364352
// Cache miss — create new entry
@@ -371,9 +359,7 @@ function handleSwitchFile(data) {
371359
const entry = docCache.getEntry(filePath);
372360
if (entry) {
373361
entry._scrollSourceLine = _pendingReloadScroll.scrollSourceLine;
374-
entry._editMode = _pendingReloadScroll.editMode;
375362
}
376-
const restoreEditMode = _pendingReloadScroll.editMode;
377363
_pendingReloadScroll = null;
378364

379365
setState({
@@ -394,10 +380,6 @@ function handleSwitchFile(data) {
394380
}
395381
});
396382
}
397-
398-
if (restoreEditMode) {
399-
setState({ editMode: true });
400-
}
401383
} else {
402384
setState({
403385
currentContent: markdown,
@@ -407,6 +389,11 @@ function handleSwitchFile(data) {
407389
}
408390
}
409391

392+
// Re-enter edit mode on the new DOM if the frame was in edit mode
393+
if (wasEditMode) {
394+
setState({ editMode: true });
395+
}
396+
410397
_suppressContentChange = false;
411398
}
412399

@@ -438,11 +425,11 @@ function handleCloseFile(data) {
438425
*/
439426
function handleReloadFile(data) {
440427
const { filePath } = data;
441-
if (!filePath) return;
428+
if (!filePath) {
429+
return;
430+
}
442431

443432
const entry = docCache.getEntry(filePath);
444-
const savedScrollPos = entry ? entry.scrollPos : 0;
445-
const wasEditMode = entry ? entry._editMode : false;
446433

447434
// If this is the active file, save current scroll
448435
if (docCache.getActiveFilePath() === filePath) {
@@ -454,7 +441,7 @@ function handleReloadFile(data) {
454441
setState({ editMode: false });
455442
}
456443
docCache.removeEntry(filePath);
457-
_pendingReloadScroll = { filePath, scrollSourceLine, editMode: wasEditMode };
444+
_pendingReloadScroll = { filePath, scrollSourceLine };
458445
}
459446
} else {
460447
docCache.removeEntry(filePath);

src-mdviewer/src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"bold": "Bold ({mod}+B)",
5959
"italic": "Italic ({mod}+I)",
6060
"strikethrough": "Strikethrough ({mod}+Shift+X)",
61-
"underline": "Underline",
61+
"underline": "Underline ({mod}+U)",
6262
"code": "Inline code ({mod}+E)",
6363
"link": "Link ({mod}+K)",
6464
"bullet_list": "Bullet list",

0 commit comments

Comments
 (0)