Skip to content

Commit 977baa3

Browse files
ryu1knclaude
andcommitted
Improve "Compare Text in Visible Editors" error message
Clarify that users need a split view with exactly 2 editors open, and show how many editors are currently visible. Also update README to remove the misleading "(i.e. tabs)" wording. Relates to #35, #76 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dec410d commit 977baa3

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Multi cursor text selection.
77
* User defined text normalization rules to reduce the noise in the diff (e.g. replace tab characters to spaces).
88
* User defined text normalization rules can be toggled off without removing them from the configuration.
9-
* Compare text in 2 visible editors (i.e. tabs) with one action.
9+
* Compare text in 2 visible editors in a split view with one action.
1010

1111
![Compare two text selections](https://raw.githubusercontent.com/ryu1kn/vscode-partial-diff/main/images/public.gif)
1212

@@ -35,7 +35,7 @@ A couple of requests from me when you raise an github issue.
3535

3636
* `Compare Text in Visible Editors` (**Command ID:** `extension.partialDiff.diffVisibleEditors`)
3737

38-
Compares text in 2 visible editors.
38+
Compares text in 2 visible editors. Split your editor to show exactly 2 files before running this command.
3939

4040
* `Toggle Pre-Comparison Text Normalization Rules` (**Command ID:** `extension.partialDiff.togglePreComparisonTextNormalizationRules`)
4141

src/lib/commands/compare-visible-editors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default class CompareVisibleEditorsCommand implements Command {
1313
async execute() {
1414
const editors = this.windowAdaptor.visibleTextEditors;
1515
if (editors.length !== 2) {
16-
this.windowAdaptor.showInformationMessage('Please first open 2 documents to compare.');
16+
this.windowAdaptor.showInformationMessage(
17+
`This command requires exactly 2 visible editors, but ${editors.length} is/are currently open. Please split your editor to show 2 files (either horizontally or vertically) and try again.`
18+
);
1719
return;
1820
}
1921

src/test/lib/commands/compare-visible-editors.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,28 @@ suite('CompareVisibleEditorsCommand', () => {
6060
});
6161
});
6262

63-
test('it tells you that it needs 2 visible editors', async () => {
63+
test('it tells you that it needs 2 visible editors when fewer are open', async () => {
6464
const {command, deps} = createCommand([editor1]);
6565
await command.execute();
6666

67-
verify(deps.windowAdaptor.showInformationMessage('Please first open 2 documents to compare.'));
67+
verify(deps.windowAdaptor.showInformationMessage(
68+
'This command requires exactly 2 visible editors, but 1 is/are currently open. Please split your editor to show 2 files (either horizontally or vertically) and try again.'
69+
));
70+
});
71+
72+
test('it tells you that it needs 2 visible editors when more than 2 are open', async () => {
73+
const editor3 = mockType<TextEditor>({
74+
viewColumn: 3,
75+
selectedText: 'SELECTED_TEXT_3',
76+
fileName: 'FILE3',
77+
selectedLineRanges: [{start: 25, end: 30}]
78+
});
79+
const {command, deps} = createCommand([editor1, editor2, editor3]);
80+
await command.execute();
81+
82+
verify(deps.windowAdaptor.showInformationMessage(
83+
'This command requires exactly 2 visible editors, but 3 is/are currently open. Please split your editor to show 2 files (either horizontally or vertically) and try again.'
84+
));
6885
});
6986

7087
function createCommand(visibleTextEditors: TextEditor[]) {

0 commit comments

Comments
 (0)