Skip to content

Commit a65e2d6

Browse files
authored
NES: Injected text fix using css (microsoft#239216)
fixes microsoft/vscode-copilot#12426
1 parent 90234e7 commit a65e2d6

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/inlineDiffView.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,30 @@ export class OriginalEditorInlineDiffView extends Disposable implements IInlineE
214214
}
215215
if (useInlineDiff) {
216216
const insertedText = modified.getValueOfRange(i.modifiedRange);
217-
originalDecorations.push({
218-
range: Range.fromPositions(i.originalRange.getEndPosition()),
219-
options: {
220-
description: 'inserted-text',
221-
before: {
222-
content: insertedText,
223-
inlineClassName: classNames(
224-
'inlineCompletions-char-insert',
225-
i.modifiedRange.isSingleLine() && diff.mode === 'insertionInline' && 'single-line-inline'
226-
),
227-
},
228-
zIndex: 2,
229-
showIfCollapsed: true,
230-
}
231-
});
217+
// when the injected text becomes long, the editor will split it into multiple spans
218+
// to be able to get the border around the start and end of the text, we need to split it into multiple segments
219+
const textSegments = insertedText.length > 3 ?
220+
[{ text: insertedText.slice(0, 1), extraClasses: ['start'] }, { text: insertedText.slice(1, -1), extraClasses: [] }, { text: insertedText.slice(-1), extraClasses: ['end'] }] :
221+
[{ text: insertedText, extraClasses: ['start', 'end'] }];
222+
223+
for (const { text, extraClasses } of textSegments) {
224+
originalDecorations.push({
225+
range: Range.fromPositions(i.originalRange.getEndPosition()),
226+
options: {
227+
description: 'inserted-text',
228+
before: {
229+
content: text,
230+
inlineClassName: classNames(
231+
'inlineCompletions-char-insert',
232+
i.modifiedRange.isSingleLine() && diff.mode === 'insertionInline' && 'single-line-inline',
233+
...extraClasses // include extraClasses for additional styling if provided
234+
),
235+
},
236+
zIndex: 2,
237+
showIfCollapsed: true,
238+
}
239+
});
240+
}
232241
}
233242
}
234243
}

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/view.css

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,36 @@
173173
border-left: solid var(--vscode-inlineEdit-modifiedChangedTextBackground) 3px;
174174
}
175175

176-
.inlineCompletions-char-delete.single-line-inline,
177-
.inlineCompletions-char-insert.single-line-inline {
176+
.inlineCompletions-char-delete.single-line-inline { /* Editor Decoration */
178177
border-radius: 4px;
179178
border: 1px solid var(--vscode-editorHoverWidget-border);
179+
margin: -2px 0 0 -2px;
180180
padding: 2px;
181181
}
182182

183+
.inlineCompletions-char-insert.single-line-inline { /* Inline Decoration */
184+
padding: 2px 0;
185+
border-top: 1px solid var(--vscode-editorHoverWidget-border);
186+
border-bottom: 1px solid var(--vscode-editorHoverWidget-border);
187+
}
188+
.inlineCompletions-char-insert.single-line-inline.start {
189+
padding-left: 2px;
190+
border-top-left-radius: 4px;
191+
border-bottom-left-radius: 4px;
192+
border-left: 1px solid var(--vscode-editorHoverWidget-border);
193+
}
194+
.inlineCompletions-char-insert.single-line-inline.end {
195+
padding-right: 2px;
196+
border-top-right-radius: 4px;
197+
border-bottom-right-radius: 4px;
198+
border-right: 1px solid var(--vscode-editorHoverWidget-border);
199+
}
200+
183201
.inlineCompletions-char-delete.single-line-inline.empty,
184202
.inlineCompletions-char-insert.single-line-inline.empty {
185203
display: none;
186204
}
187205

188-
/* Adjustments due to being a decoration */
189-
.inlineCompletions-char-delete.single-line-inline {
190-
margin: -2px 0 0 -2px;
191-
}
192-
193206
.inlineCompletions.strike-through {
194207
text-decoration-thickness: 1px;
195208
}

0 commit comments

Comments
 (0)