diff --git a/src/vs/editor/contrib/suggest/browser/suggest.ts b/src/vs/editor/contrib/suggest/browser/suggest.ts index 06e412ef142..468a6645a33 100644 --- a/src/vs/editor/contrib/suggest/browser/suggest.ts +++ b/src/vs/editor/contrib/suggest/browser/suggest.ts @@ -33,6 +33,7 @@ export const Context = { Visible: historyNavigationVisible, HasFocusedSuggestion: new RawContextKey('suggestWidgetHasFocusedSuggestion', false, localize('suggestWidgetHasSelection', "Whether any suggestion is focused")), DetailsVisible: new RawContextKey('suggestWidgetDetailsVisible', false, localize('suggestWidgetDetailsVisible', "Whether suggestion details are visible")), + DetailsFocused: new RawContextKey('suggestWidgetDetailsFocused', false, localize('suggestWidgetDetailsFocused', "Whether the details pane of the suggest widget has focus")), MultipleSuggestions: new RawContextKey('suggestWidgetMultipleSuggestions', false, localize('suggestWidgetMultipleSuggestions', "Whether there are multiple suggestions to pick from")), MakesTextEdit: new RawContextKey('suggestionMakesTextEdit', true, localize('suggestionMakesTextEdit', "Whether inserting the current suggestion yields in a change or has everything already been typed")), AcceptSuggestionsOnEnter: new RawContextKey('acceptSuggestionOnEnter', true, localize('acceptSuggestionOnEnter', "Whether suggestions are inserted when pressing Enter")), diff --git a/src/vs/editor/contrib/suggest/browser/suggestController.ts b/src/vs/editor/contrib/suggest/browser/suggestController.ts index 95639548d0c..32a46a14c99 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestController.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestController.ts @@ -9,9 +9,7 @@ import { CancellationTokenSource } from '../../../../base/common/cancellation.js import { onUnexpectedError, onUnexpectedExternalError } from '../../../../base/common/errors.js'; import { Emitter, Event } from '../../../../base/common/event.js'; import { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js'; -import { KeyCodeChord } from '../../../../base/common/keybindings.js'; import { DisposableStore, dispose, IDisposable, MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js'; -import * as platform from '../../../../base/common/platform.js'; import { StopWatch } from '../../../../base/common/stopwatch.js'; import { assertType, isObject } from '../../../../base/common/types.js'; import { StableEditorScrollState } from '../../../browser/stableEditorScroll.js'; @@ -214,21 +212,6 @@ export class SuggestController implements IEditorContribution { ctxCanResolve.set(Boolean(item.provider.resolveCompletionItem) || Boolean(item.completion.documentation) || item.completion.detail !== item.completion.label); })); - this._toDispose.add(widget.onDetailsKeyDown(e => { - // cmd + c on macOS, ctrl + c on Win / Linux - if ( - e.toKeyCodeChord().equals(new KeyCodeChord(true, false, false, false, KeyCode.KeyC)) || - (platform.isMacintosh && e.toKeyCodeChord().equals(new KeyCodeChord(false, false, false, true, KeyCode.KeyC))) - ) { - e.stopPropagation(); - return; - } - - if (!e.toKeyCodeChord().isModifierKey()) { - this.editor.focus(); - } - })); - if (this._wantsForceRenderingAbove) { widget.forceRenderingAbove(); } @@ -1126,6 +1109,24 @@ registerEditorCommand(new SuggestCommand({ })); +registerEditorCommand(new class extends EditorCommand { + constructor() { + super({ + id: 'suggestWidgetCopy', + precondition: SuggestContext.DetailsFocused, + kbOpts: { + weight: weight + 10, + kbExpr: SuggestContext.DetailsFocused, + primary: KeyMod.CtrlCmd | KeyCode.KeyC, + win: { primary: KeyMod.CtrlCmd | KeyCode.KeyC, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] } + } + }); + } + runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { + getWindow(editor.getDomNode()).document.execCommand('copy'); + } +}()); + registerEditorAction(class extends EditorAction { constructor() { diff --git a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts index 012df469c9d..0d60b6c3f57 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts @@ -130,6 +130,7 @@ export class SuggestWidget implements IDisposable { private readonly _ctxSuggestWidgetDetailsVisible: IContextKey; private readonly _ctxSuggestWidgetMultipleSuggestions: IContextKey; private readonly _ctxSuggestWidgetHasFocusedSuggestion: IContextKey; + private readonly _ctxSuggestWidgetDetailsFocused: IContextKey; private readonly _showTimeout = new TimeoutTimer(); private readonly _disposables = new DisposableStore(); @@ -292,6 +293,12 @@ export class SuggestWidget implements IDisposable { this._ctxSuggestWidgetDetailsVisible = SuggestContext.DetailsVisible.bindTo(_contextKeyService); this._ctxSuggestWidgetMultipleSuggestions = SuggestContext.MultipleSuggestions.bindTo(_contextKeyService); this._ctxSuggestWidgetHasFocusedSuggestion = SuggestContext.HasFocusedSuggestion.bindTo(_contextKeyService); + this._ctxSuggestWidgetDetailsFocused = SuggestContext.DetailsFocused.bindTo(_contextKeyService); + + const detailsFocusTracker = dom.trackFocus(this._details.widget.domNode); + this._disposables.add(detailsFocusTracker); + this._disposables.add(detailsFocusTracker.onDidFocus(() => this._ctxSuggestWidgetDetailsFocused.set(true))); + this._disposables.add(detailsFocusTracker.onDidBlur(() => this._ctxSuggestWidgetDetailsFocused.set(false))); this._disposables.add(dom.addStandardDisposableListener(this._details.widget.domNode, 'keydown', e => { this._onDetailsKeydown.fire(e);