From e9e3e7a3807d51adb72afed85e1a366b5572dab6 Mon Sep 17 00:00:00 2001 From: Benjamin Christopher Simmonds <44439583+benibenj@users.noreply.github.com> Date: Wed, 14 May 2025 12:47:17 +0200 Subject: [PATCH] Tab accepts when in accept flow and and suggestion is visible even when curosr not at suggestion (#248918) * Tab should always accept when in accept flow * only one tab to accept when inside viewport when it appears --- .../browser/model/inlineCompletionsModel.ts | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts b/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts index 6eeb971b535..7e036e8f0ef 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts @@ -412,6 +412,28 @@ export class InlineCompletionsModel extends Disposable { } return v?.primaryGhostText; }); + + this._jumpedToId = observableValue(this, undefined); + this._inAcceptFlow = observableValue(this, false); + this.inAcceptFlow = this._inAcceptFlow; + + // When the suggestion appeared, was it inside the view port or not + const appearedInsideViewport = derived(this, reader => { + const state = this.state.read(reader); + if (!state || !state.inlineCompletion) { + return false; + } + + const targetRange = state.inlineCompletion.targetRange; + const visibleRanges = this._editorObs.editor.getVisibleRanges(); + if (visibleRanges.length < 1) { + return false; + } + + const viewportRange = new Range(visibleRanges[0].startLineNumber, visibleRanges[0].startColumn, visibleRanges[visibleRanges.length - 1].endLineNumber, visibleRanges[visibleRanges.length - 1].endColumn); + return viewportRange.containsRange(targetRange); + }); + this.showCollapsed = derived(this, reader => { const state = this.state.read(reader); if (!state || state.kind !== 'inlineEdit') { @@ -466,6 +488,10 @@ export class InlineCompletionsModel extends Disposable { return true; } + if (this._inAcceptFlow.read(reader) && appearedInsideViewport.read(reader)) { + return false; + } + return !s.cursorAtInlineEdit.read(reader); }); this.tabShouldAcceptInlineEdit = derived(this, reader => { @@ -476,6 +502,9 @@ export class InlineCompletionsModel extends Disposable { if (this.showCollapsed.read(reader)) { return false; } + if (this._inAcceptFlow.read(reader) && appearedInsideViewport.read(reader)) { + return true; + } if (s.inlineCompletion.targetRange.startLineNumber === this._editorObs.cursorLineNumber.read(reader)) { return true; } @@ -488,9 +517,6 @@ export class InlineCompletionsModel extends Disposable { return s.cursorAtInlineEdit.read(reader); }); - this._jumpedToId = observableValue(this, undefined); - this._inAcceptFlow = observableValue(this, false); - this.inAcceptFlow = this._inAcceptFlow; this._register(recomputeInitiallyAndOnChange(this._fetchInlineCompletionsPromise));