Skip to content

Commit 32744a0

Browse files
committed
Fixes microsoft#135440 by allowing the preselection range to be longer than the range of the preselected item.
1 parent 1c0447f commit 32744a0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/vs/editor/contrib/inlineCompletions/suggestWidgetInlineCompletionProvider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class SuggestWidgetInlineCompletionProvider extends Disposable {
9494
return undefined;
9595
}
9696
const valid =
97-
normalizedSuggestItem.range.equalsRange(normalizedItemToPreselect.range) &&
97+
rangeStartsWith(normalizedItemToPreselect.range, normalizedSuggestItem.range) &&
9898
normalizedItemToPreselect.text.startsWith(normalizedSuggestItem.text);
9999
return { index, valid, prefixLength: normalizedSuggestItem.text.length, suggestItem };
100100
})
@@ -190,6 +190,16 @@ export class SuggestWidgetInlineCompletionProvider extends Disposable {
190190
}
191191
}
192192

193+
function rangeStartsWith(rangeToTest: Range, prefix: Range): boolean {
194+
return (
195+
rangeToTest.startLineNumber === prefix.startLineNumber &&
196+
rangeToTest.startColumn === prefix.startColumn &&
197+
(rangeToTest.endLineNumber < prefix.endLineNumber ||
198+
(rangeToTest.endLineNumber === prefix.endLineNumber &&
199+
rangeToTest.endColumn <= prefix.endColumn))
200+
);
201+
}
202+
193203
function suggestionToInlineCompletion(suggestController: SuggestController, position: Position, item: CompletionItem, toggleMode: boolean): NormalizedInlineCompletion | undefined {
194204
// additionalTextEdits might not be resolved here, this could be problematic.
195205
if (Array.isArray(item.completion.additionalTextEdits) && item.completion.additionalTextEdits.length > 0) {

0 commit comments

Comments
 (0)