Skip to content

Commit 4553268

Browse files
committed
Pass in the line mapper factory to the ViewModel
1 parent 67acfd6 commit 4553268

7 files changed

Lines changed: 34 additions & 25 deletions

File tree

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
5050
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
5151
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
5252
import { withNullAsUndefined } from 'vs/base/common/types';
53+
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
5354

5455
let EDITOR_ID = 0;
5556

@@ -1329,7 +1330,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
13291330

13301331
model.onBeforeAttached();
13311332

1332-
const viewModel = new ViewModel(this._id, this._configuration, model, (callback) => dom.scheduleAtNextAnimationFrame(callback));
1333+
const viewModel = new ViewModel(this._id, this._configuration, model, CharacterHardWrappingLineMapperFactory.create(this._configuration.options), (callback) => dom.scheduleAtNextAnimationFrame(callback));
13331334

13341335
listenersToRemove.push(model.onDidChangeDecorations((e) => this._onDidChangeModelDecorations.fire(e)));
13351336
listenersToRemove.push(model.onDidChangeLanguage((e) => {

src/vs/editor/common/viewModel/characterHardWrappingLineMapper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { CharCode } from 'vs/base/common/charCode';
77
import * as strings from 'vs/base/common/strings';
8-
import { WrappingIndent } from 'vs/editor/common/config/editorOptions';
8+
import { WrappingIndent, IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions';
99
import { CharacterClassifier } from 'vs/editor/common/core/characterClassifier';
1010
import { toUint32Array } from 'vs/base/common/uint';
1111
import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer';
@@ -56,6 +56,14 @@ class WrappingCharacterClassifier extends CharacterClassifier<CharacterClass> {
5656

5757
export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactory {
5858

59+
public static create(options: IComputedEditorOptions): CharacterHardWrappingLineMapperFactory {
60+
return new CharacterHardWrappingLineMapperFactory(
61+
options.get(EditorOption.wordWrapBreakBeforeCharacters),
62+
options.get(EditorOption.wordWrapBreakAfterCharacters),
63+
options.get(EditorOption.wordWrapBreakObtrusiveCharacters)
64+
);
65+
}
66+
5967
private readonly classifier: WrappingCharacterClassifier;
6068

6169
constructor(breakBeforeChars: string, breakAfterChars: string, breakObtrusiveChars: string) {

src/vs/editor/common/viewModel/viewModelImpl.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { tokenizeLineToHTML } from 'vs/editor/common/modes/textToHtmlTokenizer';
1818
import { MinimapTokensColorTracker } from 'vs/editor/common/viewModel/minimapTokensColorTracker';
1919
import * as viewEvents from 'vs/editor/common/view/viewEvents';
2020
import { ViewLayout } from 'vs/editor/common/viewLayout/viewLayout';
21-
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
22-
import { IViewModelLinesCollection, IdentityLinesCollection, SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection';
21+
import { IViewModelLinesCollection, IdentityLinesCollection, SplitLinesCollection, ILineMapperFactory } from 'vs/editor/common/viewModel/splitLinesCollection';
2322
import { ICoordinatesConverter, IOverviewRulerDecorations, IViewModel, MinimapLinesRenderingData, ViewLineData, ViewLineRenderingData, ViewModelDecoration } from 'vs/editor/common/viewModel/viewModel';
2423
import { ViewModelDecorations } from 'vs/editor/common/viewModel/viewModelDecorations';
2524
import { ITheme } from 'vs/platform/theme/common/themeService';
@@ -43,7 +42,13 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
4342
public readonly viewLayout: ViewLayout;
4443
private readonly decorations: ViewModelDecorations;
4544

46-
constructor(editorId: number, configuration: editorCommon.IConfiguration, model: ITextModel, scheduleAtNextAnimationFrame: (callback: () => void) => IDisposable) {
45+
constructor(
46+
editorId: number,
47+
configuration: editorCommon.IConfiguration,
48+
model: ITextModel,
49+
lineMapperFactory: ILineMapperFactory,
50+
scheduleAtNextAnimationFrame: (callback: () => void) => IDisposable
51+
) {
4752
super();
4853

4954
this.editorId = editorId;
@@ -63,20 +68,11 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
6368
const options = this.configuration.options;
6469
const wrappingInfo = options.get(EditorOption.wrappingInfo);
6570
const fontInfo = options.get(EditorOption.fontInfo);
66-
const wordWrapBreakAfterCharacters = options.get(EditorOption.wordWrapBreakAfterCharacters);
67-
const wordWrapBreakBeforeCharacters = options.get(EditorOption.wordWrapBreakBeforeCharacters);
68-
const wordWrapBreakObtrusiveCharacters = options.get(EditorOption.wordWrapBreakObtrusiveCharacters);
6971
const wrappingIndent = options.get(EditorOption.wrappingIndent);
7072

71-
let hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory(
72-
wordWrapBreakBeforeCharacters,
73-
wordWrapBreakAfterCharacters,
74-
wordWrapBreakObtrusiveCharacters
75-
);
76-
7773
this.lines = new SplitLinesCollection(
7874
this.model,
79-
hardWrappingLineMapperFactory,
75+
lineMapperFactory,
8076
this.model.getOptions().tabSize,
8177
wrappingInfo.wrappingColumn,
8278
fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth,

src/vs/editor/test/browser/commands/sideEditing.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { TextModel } from 'vs/editor/common/model/textModel';
1414
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
1515
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
1616
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
17+
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
1718

1819
function testCommand(lines: string[], selections: Selection[], edits: IIdentifiedSingleEditOperation[], expectedLines: string[], expectedSelections: Selection[]): void {
1920
withTestCodeEditor(lines, {}, (editor, cursor) => {
@@ -200,7 +201,7 @@ suite('SideEditing', () => {
200201
function _runTest(selection: Selection, editRange: Range, editText: string, editForceMoveMarkers: boolean, expected: Selection, msg: string): void {
201202
const model = TextModel.createFromString(LINES.join('\n'));
202203
const config = new TestConfiguration({});
203-
const viewModel = new ViewModel(0, config, model, null!);
204+
const viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
204205
const cursor = new Cursor(config, model, viewModel);
205206

206207
cursor.setSelections('tests', [selection]);

src/vs/editor/test/browser/controller/cursor.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { IRelaxedTextModelCreationOptions, createTextModel } from 'vs/editor/tes
2525
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
2626
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
2727
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
28+
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
2829

2930
const H = Handler;
3031

@@ -152,7 +153,7 @@ suite('Editor Controller - Cursor', () => {
152153

153154
thisModel = createTextModel(text);
154155
thisConfiguration = new TestConfiguration({});
155-
thisViewModel = new ViewModel(0, thisConfiguration, thisModel, null!);
156+
thisViewModel = new ViewModel(0, thisConfiguration, thisModel, CharacterHardWrappingLineMapperFactory.create(thisConfiguration.options), null!);
156157

157158
thisCursor = new Cursor(thisConfiguration, thisModel, thisViewModel);
158159
});
@@ -776,7 +777,7 @@ suite('Editor Controller - Cursor', () => {
776777
'var newer = require("gulp-newer");',
777778
].join('\n'));
778779
const config = new TestConfiguration({});
779-
const viewModel = new ViewModel(0, config, model, null!);
780+
const viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
780781
const cursor = new Cursor(config, model, viewModel);
781782

782783
moveTo(cursor, 1, 4, false);
@@ -816,7 +817,7 @@ suite('Editor Controller - Cursor', () => {
816817
'<property id="SomeThing" key="SomeKey" value="00X"/>',
817818
].join('\n'));
818819
const config = new TestConfiguration({});
819-
const viewModel = new ViewModel(0, config, model, null!);
820+
const viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
820821
const cursor = new Cursor(config, model, viewModel);
821822

822823
moveTo(cursor, 10, 10, false);
@@ -880,7 +881,7 @@ suite('Editor Controller - Cursor', () => {
880881
'<property id="SomeThing" key="SomeKey" value="00X"/>',
881882
].join('\n'));
882883
const config = new TestConfiguration({});
883-
const viewModel = new ViewModel(0, config, model, null!);
884+
const viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
884885
const cursor = new Cursor(config, model, viewModel);
885886

886887
moveTo(cursor, 10, 10, false);
@@ -929,7 +930,7 @@ suite('Editor Controller - Cursor', () => {
929930
'var newer = require("gulp-newer");',
930931
].join('\n'));
931932
const config = new TestConfiguration({});
932-
const viewModel = new ViewModel(0, config, model, null!);
933+
const viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
933934
const cursor = new Cursor(config, model, viewModel);
934935

935936
moveTo(cursor, 1, 4, false);
@@ -2074,7 +2075,7 @@ suite('Editor Controller - Regression tests', () => {
20742075
wordWrap: 'wordWrapColumn',
20752076
wordWrapColumn: 100
20762077
});
2077-
const viewModel = new ViewModel(0, config, model, null!);
2078+
const viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
20782079
const cursor = new Cursor(config, model, viewModel);
20792080

20802081
moveTo(cursor, 1, 43, false);
@@ -3834,7 +3835,7 @@ function usingCursor(opts: ICursorOpts, callback: (model: TextModel, cursor: Cur
38343835
let model = createTextModel(opts.text.join('\n'), opts.modelOpts, opts.languageIdentifier);
38353836
model.forceTokenization(model.getLineCount());
38363837
let config = new TestConfiguration(opts.editorOpts || {});
3837-
let viewModel = new ViewModel(0, config, model, null!);
3838+
let viewModel = new ViewModel(0, config, model, CharacterHardWrappingLineMapperFactory.create(config.options), null!);
38383839
let cursor = new Cursor(config, model, viewModel);
38393840

38403841
callback(model, cursor);

src/vs/editor/test/browser/controller/cursorMoveCommand.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Selection } from 'vs/editor/common/core/selection';
1313
import { TextModel } from 'vs/editor/common/model/textModel';
1414
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
1515
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
16+
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
1617

1718
suite('Cursor move command test', () => {
1819

@@ -32,7 +33,7 @@ suite('Cursor move command test', () => {
3233

3334
thisModel = TextModel.createFromString(text);
3435
thisConfiguration = new TestConfiguration({});
35-
thisViewModel = new ViewModel(0, thisConfiguration, thisModel, null!);
36+
thisViewModel = new ViewModel(0, thisConfiguration, thisModel, CharacterHardWrappingLineMapperFactory.create(thisConfiguration.options), null!);
3637
thisCursor = new Cursor(thisConfiguration, thisModel, thisViewModel);
3738
});
3839

src/vs/editor/test/common/viewModel/testViewModel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
77
import { TextModel } from 'vs/editor/common/model/textModel';
88
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
99
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
10+
import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
1011

1112
export function testViewModel(text: string[], options: IEditorOptions, callback: (viewModel: ViewModel, model: TextModel) => void): void {
1213
const EDITOR_ID = 1;
@@ -15,7 +16,7 @@ export function testViewModel(text: string[], options: IEditorOptions, callback:
1516

1617
let model = TextModel.createFromString(text.join('\n'));
1718

18-
let viewModel = new ViewModel(EDITOR_ID, configuration, model, null!);
19+
let viewModel = new ViewModel(EDITOR_ID, configuration, model, CharacterHardWrappingLineMapperFactory.create(configuration.options), null!);
1920

2021
callback(viewModel, model);
2122

0 commit comments

Comments
 (0)