提交 a3b97734 编写于 作者: A Alex Dima

Fixes #21073: SplitLinesCollection: attempt to access a 'newer' model

上级 31452516
......@@ -255,7 +255,7 @@ export class ViewModel implements IViewModel {
public getCenteredRangeInViewport(): Range {
if (this._centeredViewLine === -1) {
// Never got rendered
// Never got rendered or not rendered since last content change event
return null;
}
let viewLineNumber = this._centeredViewLine;
......@@ -267,6 +267,7 @@ export class ViewModel implements IViewModel {
const containsModelContentChangeEvent = ViewModel._containsModelContentChangeEvent(events);
if (containsModelContentChangeEvent) {
this._centeredViewLine = -1;
this.configuration.setMaxLineNumber(this.model.getLineCount());
}
......@@ -284,23 +285,18 @@ export class ViewModel implements IViewModel {
previousCenteredModelRange = this.getCenteredRangeInViewport();
}
let i: number,
len: number,
e: EmitterEvent,
data: any,
modelContentChangedEvent: editorCommon.IModelContentChangedEvent,
hadOtherModelChange = false,
hadModelLineChangeThatChangedLineMapping = false,
revealPreviousCenteredModelRange = false;
let hadOtherModelChange = false;
let hadModelLineChangeThatChangedLineMapping = false;
let revealPreviousCenteredModelRange = false;
for (i = 0, len = events.length; i < len; i++) {
e = events[i];
data = e.getData();
for (let i = 0, len = events.length; i < len; i++) {
let e = events[i];
let data = e.getData();
switch (e.getType()) {
case editorCommon.EventType.ModelRawContentChanged:
modelContentChangedEvent = <editorCommon.IModelContentChangedEvent>data;
let modelContentChangedEvent = <editorCommon.IModelContentChangedEvent>data;
switch (modelContentChangedEvent.changeType) {
case editorCommon.EventType.ModelRawContentChangedFlush:
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Model } from 'vs/editor/common/model/model';
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
import { MockConfiguration } from 'vs/editor/test/common/mocks/mockConfiguration';
import { SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection';
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
import * as editorCommon from 'vs/editor/common/editorCommon';
export function testViewModel(text: string[], options: editorCommon.ICodeEditorWidgetCreationOptions, callback: (viewModel: ViewModel, model: Model) => void): void {
const EDITOR_ID = 1;
let configuration = new MockConfiguration(options);
let model = Model.createFromString(text.join('\n'));
let factory = new CharacterHardWrappingLineMapperFactory(
configuration.editor.wrappingInfo.wordWrapBreakBeforeCharacters,
configuration.editor.wrappingInfo.wordWrapBreakAfterCharacters,
configuration.editor.wrappingInfo.wordWrapBreakObtrusiveCharacters
);
let linesCollection = new SplitLinesCollection(
model,
factory,
model.getOptions().tabSize,
configuration.editor.wrappingInfo.wrappingColumn,
configuration.editor.fontInfo.typicalFullwidthCharacterWidth / configuration.editor.fontInfo.typicalHalfwidthCharacterWidth,
configuration.editor.wrappingInfo.wrappingIndent
);
let viewModel = new ViewModel(
linesCollection,
EDITOR_ID,
configuration,
model
);
callback(viewModel, model);
viewModel.dispose();
model.dispose();
configuration.dispose();
}
......@@ -5,63 +5,18 @@
'use strict';
import * as assert from 'assert';
import { Model } from 'vs/editor/common/model/model';
import { Range } from 'vs/editor/common/core/range';
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
import { MockConfiguration } from 'vs/editor/test/common/mocks/mockConfiguration';
import { SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection';
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
import { testViewModel } from 'vs/editor/test/common/viewModel/testViewModel';
suite('ViewModelDecorations', () => {
interface ITestViewModelOpts {
wrappingColumn: number;
text: string;
}
function withTestViewModel(opts: ITestViewModelOpts, callback: (viewModel: ViewModel, model: Model) => void): void {
const EDITOR_ID = 1;
let configuration = new MockConfiguration({
wrappingColumn: opts.wrappingColumn
});
let model = Model.createFromString(opts.text);
let factory = new CharacterHardWrappingLineMapperFactory(
configuration.editor.wrappingInfo.wordWrapBreakBeforeCharacters,
configuration.editor.wrappingInfo.wordWrapBreakAfterCharacters,
configuration.editor.wrappingInfo.wordWrapBreakObtrusiveCharacters
);
let linesCollection = new SplitLinesCollection(
model,
factory,
model.getOptions().tabSize,
configuration.editor.wrappingInfo.wrappingColumn,
configuration.editor.fontInfo.typicalFullwidthCharacterWidth / configuration.editor.fontInfo.typicalHalfwidthCharacterWidth,
configuration.editor.wrappingInfo.wrappingIndent
);
let viewModel = new ViewModel(
linesCollection,
EDITOR_ID,
configuration,
model
);
callback(viewModel, model);
viewModel.dispose();
model.dispose();
configuration.dispose();
}
test('getDecorationsViewportData', () => {
withTestViewModel({
text: 'hello world, this is a buffer that will be wrapped',
const text = [
'hello world, this is a buffer that will be wrapped'
];
const opts = {
wrappingColumn: 13
}, (viewModel, model) => {
};
testViewModel(text, opts, (viewModel, model) => {
assert.equal(viewModel.getLineContent(1), 'hello world, ');
assert.equal(viewModel.getLineContent(2), 'this is a ');
assert.equal(viewModel.getLineContent(3), 'buffer that ');
......@@ -309,10 +264,13 @@ suite('ViewModelDecorations', () => {
});
test('issue #17208: Problem scrolling in 1.8.0', () => {
withTestViewModel({
text: 'hello world, this is a buffer that will be wrapped',
const text = [
'hello world, this is a buffer that will be wrapped'
];
const opts = {
wrappingColumn: 13
}, (viewModel, model) => {
};
testViewModel(text, opts, (viewModel, model) => {
assert.equal(viewModel.getLineContent(1), 'hello world, ');
assert.equal(viewModel.getLineContent(2), 'this is a ');
assert.equal(viewModel.getLineContent(3), 'buffer that ');
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { Range } from 'vs/editor/common/core/range';
import { testViewModel } from 'vs/editor/test/common/viewModel/testViewModel';
suite('ViewModel', () => {
test('issue #21073: SplitLinesCollection: attempt to access a \'newer\' model', () => {
const text = [''];
const opts = {
lineNumbersMinChars: 1
};
testViewModel(text, opts, (viewModel, model) => {
assert.equal(viewModel.getLineCount(), 1);
viewModel.setViewport(1, 1, 1);
model.applyEdits([{
identifier: null,
range: new Range(1, 1, 1, 1),
text: [
'line01',
'line02',
'line03',
'line04',
'line05',
'line06',
'line07',
'line08',
'line09',
'line10',
].join('\n'),
forceMoveMarkers: false
}]);
assert.equal(viewModel.getLineCount(), 10);
});
});
});
......@@ -254,11 +254,8 @@ function main() {
// replace the default unexpected error handler to be useful during tests
loader(['vs/base/common/errors'], function(errors) {
errors.setUnexpectedErrorHandler(function (err) {
try {
throw new Error('oops');
} catch (e) {
unexpectedErrors.push((err && err.message ? err.message : err) + '\n' + e.stack);
}
let stack = (err && err.stack) || (new Error().stack);
unexpectedErrors.push((err && err.message ? err.message : err) + '\n' + stack);
});
// fire up mocha
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册