Skip to content

Commit 59bb9f0

Browse files
committed
Fix Copilot Code Review button text truncation with ellipsis
1 parent 7d2373d commit 59bb9f0

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { default as assert } from 'assert';
7+
8+
// Test the text truncation logic that should be applied to tree view button text
9+
describe('CompareChangesTreeDataProvider text truncation', () => {
10+
const MAX_BUTTON_TEXT_LENGTH = 40; // Same constant used in implementation
11+
12+
function truncateButtonText(buttonText: string): string {
13+
return buttonText.length > MAX_BUTTON_TEXT_LENGTH
14+
? buttonText.substring(0, MAX_BUTTON_TEXT_LENGTH - 3) + '...'
15+
: buttonText;
16+
}
17+
18+
describe('button text truncation', () => {
19+
it('should truncate long button text with ellipsis', () => {
20+
const longButtonText = '$(sparkle) Very Long Copilot Reviewer Name That Would Cause Overflow Issues Code Review';
21+
const result = truncateButtonText(longButtonText);
22+
23+
assert.strictEqual(result.length, MAX_BUTTON_TEXT_LENGTH);
24+
assert.ok(result.endsWith('...'));
25+
assert.ok(result.includes('$(sparkle)'));
26+
assert.ok(!result.includes('Overflow Issues Code Review'));
27+
});
28+
29+
it('should not truncate short button text', () => {
30+
const shortButtonText = '$(sparkle) Copilot Code Review';
31+
const result = truncateButtonText(shortButtonText);
32+
33+
assert.strictEqual(result, shortButtonText);
34+
assert.ok(!result.includes('...'));
35+
});
36+
37+
it('should handle exactly max length text', () => {
38+
const exactLengthText = 'A'.repeat(MAX_BUTTON_TEXT_LENGTH);
39+
const result = truncateButtonText(exactLengthText);
40+
41+
assert.strictEqual(result, exactLengthText);
42+
assert.ok(!result.includes('...'));
43+
});
44+
45+
it('should handle text that is one character over the limit', () => {
46+
const overLimitByOne = 'A'.repeat(MAX_BUTTON_TEXT_LENGTH + 1);
47+
const result = truncateButtonText(overLimitByOne);
48+
49+
assert.strictEqual(result.length, MAX_BUTTON_TEXT_LENGTH);
50+
assert.ok(result.endsWith('...'));
51+
assert.strictEqual(result, 'A'.repeat(MAX_BUTTON_TEXT_LENGTH - 3) + '...');
52+
});
53+
54+
it('should preserve sparkle icon in truncated text', () => {
55+
const longTextWithIcon = '$(sparkle) ' + 'Very '.repeat(20) + 'Long Code Review';
56+
const result = truncateButtonText(longTextWithIcon);
57+
58+
assert.ok(result.startsWith('$(sparkle)'));
59+
assert.ok(result.endsWith('...'));
60+
assert.strictEqual(result.length, MAX_BUTTON_TEXT_LENGTH);
61+
});
62+
});
63+
});

src/view/compareChangesTreeDataProvider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ class CompareChangesFilesTreeProvider extends CompareChangesTreeProvider {
264264
markdown.appendMarkdown('\n\n');
265265
}
266266
markdown.supportThemeIcons = true;
267-
markdown.appendMarkdown(`[${vscode.l10n.t('$(sparkle) {0} Code Review', preReviewer.title)}](command:pr.preReview)`);
267+
268+
// Create the button text with potential truncation for better UI in smaller panels
269+
const buttonText = vscode.l10n.t('$(sparkle) {0} Code Review', preReviewer.title);
270+
const MAX_BUTTON_TEXT_LENGTH = 40; // Reasonable length for tree view messages
271+
const truncatedButtonText = buttonText.length > MAX_BUTTON_TEXT_LENGTH
272+
? buttonText.substring(0, MAX_BUTTON_TEXT_LENGTH - 3) + '...'
273+
: buttonText;
274+
275+
markdown.appendMarkdown(`[${truncatedButtonText}](command:pr.preReview)`);
268276
return markdown;
269277
}
270278

0 commit comments

Comments
 (0)