Select target line when showing editor gutter context menu (#176667)

* Select target line when showing editor gutter context menu

* Only set selection for clicks on line numbers
This commit is contained in:
Joyce Er
2023-03-09 13:10:23 -08:00
committed by GitHub
parent fc76f309cc
commit 35ecd669ca
@@ -12,6 +12,7 @@ import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { TextEditorSelectionSource } from 'vs/platform/editor/common/editor';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
@@ -90,6 +91,22 @@ export class EditorLineNumberContextMenu extends Disposable implements IEditorCo
const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri }, shouldForwardArgs: true });
actions.push(...menuActions.map(a => a[1]));
// if the current editor selections do not contain the target line number,
// set the selection to the clicked line number
if (e.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
const currentSelections = this.editor.getSelections();
const containsSelection = currentSelections?.some(selection => selection.containsPosition({ lineNumber, column: 1 }));
if (!containsSelection) {
const selection = {
startLineNumber: lineNumber,
endLineNumber: lineNumber,
startColumn: 1,
endColumn: model.getLineLength(lineNumber) + 1
};
this.editor.setSelection(selection, TextEditorSelectionSource.PROGRAMMATIC);
}
}
this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => Separator.join(...actions),