Skip to content

Commit 0c85ba6

Browse files
committed
fix(ccb): make toolbar undo/redo work when an external surface owns focus in design mode
In design mode the active document can sit behind a surface that owns DOM focus instead of a CodeMirror editor — e.g. the markdown viewer's iframe when it's in edit mode. EditorManager.getFocusedEditor() returns null in that case, so the CCB undo/redo buttons (and anything else routing through EDIT_UNDO / EDIT_REDO) silently no-op'd even though the underlying Phoenix document had perfectly good history. When design mode is active and no editor is focused, fall back to EditorManager.getCurrentFullEditor() so toolbar undo/redo drives the active document. External surfaces that sync their edits back to that document (like the md viewer) will re-render to reflect the rolled-back text. Outside design mode the pre-existing no-op behavior is preserved.
1 parent d2c14ce commit 0c85ba6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/editor/EditorCommandHandlers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ define(function (require, exports, module) {
3333
Editor = require("editor/Editor").Editor,
3434
CommandManager = require("command/CommandManager"),
3535
EditorManager = require("editor/EditorManager"),
36+
WorkspaceManager = require("view/WorkspaceManager"),
3637
StringUtils = require("utils/StringUtils"),
3738
TokenUtils = require("utils/TokenUtils"),
3839
CodeMirror = require("thirdparty/CodeMirror/lib/codemirror"),
@@ -1185,6 +1186,16 @@ define(function (require, exports, module) {
11851186
var editor = EditorManager.getFocusedEditor();
11861187
var result = new $.Deferred();
11871188

1189+
// In design mode the active document often lives behind an external
1190+
// surface that owns DOM focus (e.g. the markdown viewer iframe in
1191+
// edit mode), so getFocusedEditor() returns null even though there
1192+
// is an underlying Phoenix editor whose doc captures the changes.
1193+
// Fall back to the active-pane full editor so toolbar undo/redo
1194+
// still drives the document's history in that state.
1195+
if (!editor && WorkspaceManager.isInDesignMode()) {
1196+
editor = EditorManager.getCurrentFullEditor();
1197+
}
1198+
11881199
if (editor) {
11891200
editor[operation]();
11901201
result.resolve();

0 commit comments

Comments
 (0)