Skip to content

Commit fc9164d

Browse files
authored
fix: Prevent loss of focus when deleting a workspace comment. (#9200)
* fix: Prevent loss of focus when deleting a workspace comment. * chore: Add test verifying workspace comment focus behavior on deletion.
1 parent 8580d76 commit fc9164d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

core/comments/delete_comment_bar_button.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import * as browserEvents from '../browser_events.js';
8+
import {getFocusManager} from '../focus_manager.js';
89
import * as touch from '../touch.js';
910
import * as dom from '../utils/dom.js';
1011
import {Svg} from '../utils/svg.js';
@@ -98,5 +99,6 @@ export class DeleteCommentBarButton extends CommentBarButton {
9899

99100
this.getParentComment().dispose();
100101
e?.stopPropagation();
102+
getFocusManager().focusNode(this.workspace);
101103
}
102104
}

tests/mocha/workspace_comment_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import {assert} from '../../node_modules/chai/chai.js';
78
import {
89
assertEventFired,
910
createChangeListenerSpy,
@@ -167,5 +168,15 @@ suite('Workspace comment', function () {
167168
this.workspace.id,
168169
);
169170
});
171+
172+
test('focuses the workspace when deleted', function () {
173+
const comment = new Blockly.comments.RenderedWorkspaceComment(
174+
this.workspace,
175+
);
176+
Blockly.getFocusManager().focusNode(comment);
177+
assert.equal(Blockly.getFocusManager().getFocusedNode(), comment);
178+
comment.view.getCommentBarButtons()[1].performAction();
179+
assert.equal(Blockly.getFocusManager().getFocusedNode(), this.workspace);
180+
});
170181
});
171182
});

0 commit comments

Comments
 (0)