mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
There must always be at least one visible line (#44805)
This commit is contained in:
parent
47497b7c5c
commit
d3e67801e3
|
@ -288,6 +288,7 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
|
|||
let hiddenAreaIdx = -1;
|
||||
let nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
|
||||
|
||||
let hasVisibleLine = false;
|
||||
for (let i = 0; i < this.lines.length; i++) {
|
||||
let lineNumber = i + 1;
|
||||
|
||||
|
@ -306,6 +307,7 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
|
|||
lineChanged = true;
|
||||
}
|
||||
} else {
|
||||
hasVisibleLine = true;
|
||||
// Line should be visible
|
||||
if (!this.lines[i].isVisible()) {
|
||||
this.lines[i] = this.lines[i].setVisible(true);
|
||||
|
@ -318,6 +320,11 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
|
|||
}
|
||||
}
|
||||
|
||||
if (!hasVisibleLine) {
|
||||
// Cannot have everything be hidden => reveal everything!
|
||||
this.setHiddenAreas([]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -465,6 +472,10 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
|
|||
|
||||
public acceptVersionId(versionId: number): void {
|
||||
this._validModelVersionId = versionId;
|
||||
if (this.lines.length === 1 && !this.lines[0].isVisible()) {
|
||||
// At least one line must be visible => reset hidden areas
|
||||
this.setHiddenAreas([]);
|
||||
}
|
||||
}
|
||||
|
||||
public getViewLineCount(): number {
|
||||
|
|
|
@ -74,6 +74,39 @@ suite('ViewModel', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('issue #44805: No visible lines via API call', () => {
|
||||
const text = [
|
||||
'line1',
|
||||
'line2',
|
||||
'line3'
|
||||
];
|
||||
testViewModel(text, {}, (viewModel, model) => {
|
||||
assert.equal(viewModel.getLineCount(), 3);
|
||||
viewModel.setHiddenAreas([new Range(1, 1, 3, 1)]);
|
||||
assert.ok(viewModel.getVisibleRanges() !== null);
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #44805: No visible lines via undoing', () => {
|
||||
const text = [
|
||||
''
|
||||
];
|
||||
testViewModel(text, {}, (viewModel, model) => {
|
||||
assert.equal(viewModel.getLineCount(), 1);
|
||||
|
||||
model.pushEditOperations([], [{
|
||||
range: new Range(1, 1, 1, 1),
|
||||
text: 'line1\nline2\nline3'
|
||||
}], () => ([]));
|
||||
|
||||
viewModel.setHiddenAreas([new Range(1, 1, 1, 1)]);
|
||||
assert.equal(viewModel.getLineCount(), 2);
|
||||
|
||||
model.undo();
|
||||
assert.ok(viewModel.getVisibleRanges() !== null);
|
||||
});
|
||||
});
|
||||
|
||||
function assertGetPlainTextToCopy(text: string[], ranges: Range[], emptySelectionClipboard: boolean, expected: string | string[]): void {
|
||||
testViewModel(text, {}, (viewModel, model) => {
|
||||
let actual = viewModel.getPlainTextToCopy(ranges, emptySelectionClipboard);
|
||||
|
|
Loading…
Reference in a new issue