Skip to content

Commit a444059

Browse files
authored
Bugfixes on Code Action Widget (microsoft#156105)
Code Action Widget bug fixes for hover and going off DOM.
2 parents 364247d + bbe0dbe commit a444059

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/vs/editor/contrib/codeAction/browser/codeActionMenu.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
146146
private focusedEnabledItem: number | undefined;
147147
private currSelectedItem: number = 0;
148148
private hasSeperator: boolean = false;
149+
private block?: HTMLElement;
149150

150151
public static readonly ID: string = 'editor.contrib.codeActionMenu';
151152

@@ -203,6 +204,20 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
203204
const renderDisposables = new DisposableStore();
204205
const renderMenu = document.createElement('div');
205206

207+
// Render invisible div to block mouse interaction in the rest of the UI
208+
const menuBlock = document.createElement('div');
209+
this.block = element.appendChild(menuBlock);
210+
this.block.classList.add('context-view-block');
211+
this.block.style.position = 'fixed';
212+
this.block.style.cursor = 'initial';
213+
this.block.style.left = '0';
214+
this.block.style.top = '0';
215+
this.block.style.width = '100%';
216+
this.block.style.height = '100%';
217+
this.block.style.zIndex = '-1';
218+
219+
renderDisposables.add(dom.addDisposableListener(this.block, dom.EventType.MOUSE_DOWN, e => e.stopPropagation()));
220+
206221
renderMenu.id = 'codeActionMenuWidget';
207222
renderMenu.classList.add('codeActionMenuWidget');
208223

@@ -263,9 +278,13 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
263278
this.codeActionList.value?.layout(height, maxWidth);
264279

265280
// List selection
266-
this.focusedEnabledItem = 0;
267-
this.currSelectedItem = this.viewItems[0].index;
268-
this.codeActionList.value.setFocus([this.currSelectedItem]);
281+
if (this.viewItems.length < 1) {
282+
this.currSelectedItem = 0;
283+
} else {
284+
this.focusedEnabledItem = 0;
285+
this.currSelectedItem = this.viewItems[0].index;
286+
this.codeActionList.value.setFocus([this.currSelectedItem]);
287+
}
269288

270289
// List Focus
271290
this.codeActionList.value.domFocus();
@@ -284,7 +303,7 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
284303
protected focusPrevious() {
285304
if (typeof this.focusedEnabledItem === 'undefined') {
286305
this.focusedEnabledItem = this.viewItems[0].index;
287-
} else if (this.viewItems.length <= 1) {
306+
} else if (this.viewItems.length < 1) {
288307
return false;
289308
}
290309

@@ -307,7 +326,7 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
307326
protected focusNext() {
308327
if (typeof this.focusedEnabledItem === 'undefined') {
309328
this.focusedEnabledItem = this.viewItems.length - 1;
310-
} else if (this.viewItems.length <= 1) {
329+
} else if (this.viewItems.length < 1) {
311330
return false;
312331
}
313332

src/vs/editor/contrib/codeAction/browser/media/action.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
border-color: none;
1919
background-color: var(--vscode-menu-background);
2020
color: var(--vscode-menu-foreground);
21+
box-shadow: rgb(0,0,0, 16%) 0px 2px 8px;
2122
}
2223

2324
.codeActionMenuWidget .monaco-list:not(.element-focused):focus:before {

0 commit comments

Comments
 (0)