Skip to content

Commit ad082bd

Browse files
authored
Restore focus when the widget is dismissed. (microsoft#205900)
* Restore focus when the widget is dismissed. * Only restore focus when the widget has focus.
1 parent 16ad3d4 commit ad082bd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,27 @@ export class NotebookChatController extends Disposable implements INotebookEdito
784784

785785

786786
dismiss() {
787+
// move focus back to the cell above
788+
if (this._widget) {
789+
const widgetIndex = this._widget.afterModelPosition;
790+
const currentFocus = this._notebookEditor.getFocus();
791+
792+
if (currentFocus.start === widgetIndex && currentFocus.end === widgetIndex) {
793+
// focus is on the widget
794+
if (widgetIndex === 0) {
795+
// on top of all cells
796+
if (this._notebookEditor.getLength() > 0) {
797+
this._notebookEditor.focusNotebookCell(this._notebookEditor.cellAt(0)!, 'container');
798+
}
799+
} else {
800+
const cell = this._notebookEditor.cellAt(widgetIndex - 1);
801+
if (cell) {
802+
this._notebookEditor.focusNotebookCell(cell, 'container');
803+
}
804+
}
805+
}
806+
}
807+
787808
this._ctxCellWidgetFocused.set(false);
788809
this._ctxUserDidEdit.set(false);
789810
this._sessionCtor?.cancel();

0 commit comments

Comments
 (0)