@@ -7,7 +7,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
77import { Emitter , Event } from 'vs/base/common/event' ;
88import * as strings from 'vs/base/common/strings' ;
99import { CursorCollection } from 'vs/editor/common/controller/cursorCollection' ;
10- import { CursorColumns , CursorConfiguration , CursorContext , CursorState , EditOperationResult , EditOperationType , IColumnSelectData , ICursors , PartialCursorState , ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon' ;
10+ import { CursorColumns , CursorConfiguration , CursorContext , CursorState , EditOperationResult , EditOperationType , IColumnSelectData , PartialCursorState , ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon' ;
1111import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations' ;
1212import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents' ;
1313import { TypeOperations , TypeWithAutoClosingCommand } from 'vs/editor/common/controller/cursorTypeOperations' ;
@@ -16,10 +16,9 @@ import { Range, IRange } from 'vs/editor/common/core/range';
1616import { ISelection , Selection , SelectionDirection } from 'vs/editor/common/core/selection' ;
1717import * as editorCommon from 'vs/editor/common/editorCommon' ;
1818import { ITextModel , TrackedRangeStickiness , IModelDeltaDecoration , ICursorStateComputer , IIdentifiedSingleEditOperation , IValidEditOperation } from 'vs/editor/common/model' ;
19- import { RawContentChangedType , ModelRawContentChangedEvent , IModelLanguageChangedEvent } from 'vs/editor/common/model/textModelEvents' ;
19+ import { RawContentChangedType , ModelRawContentChangedEvent } from 'vs/editor/common/model/textModelEvents' ;
2020import { ViewEventsCollector , VerticalRevealType , ViewCursorStateChangedEvent , ViewRevealRangeRequestEvent } from 'vs/editor/common/view/viewEvents' ;
2121import { dispose , Disposable } from 'vs/base/common/lifecycle' ;
22- import { EditorOption , ConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions' ;
2322import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel' ;
2423
2524export class CursorStateChangedEvent {
@@ -74,7 +73,7 @@ export class CursorModelState {
7473
7574 constructor ( model : ITextModel , cursor : Cursor ) {
7675 this . modelVersionId = model . getVersionId ( ) ;
77- this . cursorState = cursor . getAll ( ) ;
76+ this . cursorState = cursor . getCursorStates ( ) ;
7877 }
7978
8079 public equals ( other : CursorModelState | null ) : boolean {
@@ -162,7 +161,7 @@ class AutoClosedAction {
162161 }
163162}
164163
165- export class Cursor extends Disposable implements ICursors {
164+ export class Cursor extends Disposable {
166165
167166 public static readonly MAX_CURSOR_COUNT = 10000 ;
168167
@@ -172,7 +171,6 @@ export class Cursor extends Disposable implements ICursors {
172171 private readonly _onDidChange : Emitter < CursorStateChangedEvent > = this . _register ( new Emitter < CursorStateChangedEvent > ( ) ) ;
173172 public readonly onDidChange : Event < CursorStateChangedEvent > = this . _onDidChange . event ;
174173
175- private readonly _configuration : editorCommon . IConfiguration ;
176174 private readonly _model : ITextModel ;
177175 private _knownModelVersionId : number ;
178176 private readonly _viewModel : ICursorSimpleModel ;
@@ -188,14 +186,13 @@ export class Cursor extends Disposable implements ICursors {
188186 private _autoClosedActions : AutoClosedAction [ ] ;
189187 private _prevEditOperationType : EditOperationType ;
190188
191- constructor ( configuration : editorCommon . IConfiguration , model : ITextModel , viewModel : ICursorSimpleModel , coordinatesConverter : ICoordinatesConverter ) {
189+ constructor ( model : ITextModel , viewModel : ICursorSimpleModel , coordinatesConverter : ICoordinatesConverter , cursorConfig : CursorConfiguration ) {
192190 super ( ) ;
193- this . _configuration = configuration ;
194191 this . _model = model ;
195192 this . _knownModelVersionId = this . _model . getVersionId ( ) ;
196193 this . _viewModel = viewModel ;
197194 this . _coordinatesConverter = coordinatesConverter ;
198- this . context = new CursorContext ( this . _configuration , this . _model , this . _viewModel , this . _coordinatesConverter ) ;
195+ this . context = new CursorContext ( this . _model , this . _coordinatesConverter , cursorConfig ) ;
199196 this . _cursors = new CursorCollection ( this . context ) ;
200197
201198 this . _hasFocus = false ;
@@ -213,8 +210,8 @@ export class Cursor extends Disposable implements ICursors {
213210 super . dispose ( ) ;
214211 }
215212
216- private _updateCursorContext ( ) : void {
217- this . context = new CursorContext ( this . _configuration , this . _model , this . _viewModel , this . _coordinatesConverter ) ;
213+ public updateConfiguration ( cursorConfig : CursorConfiguration ) : void {
214+ this . context = new CursorContext ( this . _model , this . _coordinatesConverter , cursorConfig ) ;
218215 this . _cursors . updateContext ( this . context ) ;
219216 }
220217
@@ -230,25 +227,7 @@ export class Cursor extends Disposable implements ICursors {
230227 return ;
231228 }
232229 // Ensure valid state
233- this . setStates ( eventsCollector , 'viewModel' , CursorChangeReason . NotSet , this . getAll ( ) ) ;
234- }
235-
236- public onDidChangeModelLanguage ( e : IModelLanguageChangedEvent ) : void {
237- this . _updateCursorContext ( ) ;
238- }
239-
240- public onDidChangeModelLanguageConfiguration ( ) : void {
241- this . _updateCursorContext ( ) ;
242- }
243-
244- public onDidChangeModelOptions ( ) : void {
245- this . _updateCursorContext ( ) ;
246- }
247-
248- public onDidChangeConfiguration ( e : ConfigurationChangedEvent ) : void {
249- if ( CursorConfiguration . shouldRecreate ( e ) ) {
250- this . _updateCursorContext ( ) ;
251- }
230+ this . setStates ( eventsCollector , 'viewModel' , CursorChangeReason . NotSet , this . getCursorStates ( ) ) ;
252231 }
253232
254233 public setHasFocus ( hasFocus : boolean ) : void {
@@ -271,15 +250,15 @@ export class Cursor extends Disposable implements ICursors {
271250
272251 // ------ some getters/setters
273252
274- public getPrimaryCursor ( ) : CursorState {
253+ public getPrimaryCursorState ( ) : CursorState {
275254 return this . _cursors . getPrimaryCursor ( ) ;
276255 }
277256
278257 public getLastAddedCursorIndex ( ) : number {
279258 return this . _cursors . getLastAddedCursorIndex ( ) ;
280259 }
281260
282- public getAll ( ) : CursorState [ ] {
261+ public getCursorStates ( ) : CursorState [ ] {
283262 return this . _cursors . getAll ( ) ;
284263 }
285264
@@ -301,7 +280,7 @@ export class Cursor extends Disposable implements ICursors {
301280 return this . _emitStateChangedIfNecessary ( eventsCollector , source , reason , oldState , reachedMaxCursorCount ) ;
302281 }
303282
304- public setColumnSelectData ( columnSelectData : IColumnSelectData ) : void {
283+ public setCursorColumnSelectData ( columnSelectData : IColumnSelectData ) : void {
305284 this . _columnSelectData = columnSelectData ;
306285 }
307286
@@ -438,7 +417,7 @@ export class Cursor extends Disposable implements ICursors {
438417 return this . _cursors . getBottomMostViewPosition ( ) ;
439418 }
440419
441- public getColumnSelectData ( ) : IColumnSelectData {
420+ public getCursorColumnSelectData ( ) : IColumnSelectData {
442421 if ( this . _columnSelectData ) {
443422 return this . _columnSelectData ;
444423 }
@@ -448,9 +427,9 @@ export class Cursor extends Disposable implements ICursors {
448427 return {
449428 isReal : false ,
450429 fromViewLineNumber : viewSelectionStart . lineNumber ,
451- fromViewVisualColumn : CursorColumns . visibleColumnFromColumn2 ( this . context . config , this . context . viewModel , viewSelectionStart ) ,
430+ fromViewVisualColumn : CursorColumns . visibleColumnFromColumn2 ( this . context . cursorConfig , this . _viewModel , viewSelectionStart ) ,
452431 toViewLineNumber : viewPosition . lineNumber ,
453- toViewVisualColumn : CursorColumns . visibleColumnFromColumn2 ( this . context . config , this . context . viewModel , viewPosition ) ,
432+ toViewVisualColumn : CursorColumns . visibleColumnFromColumn2 ( this . context . cursorConfig , this . _viewModel , viewPosition ) ,
454433 } ;
455434 }
456435
@@ -600,7 +579,7 @@ export class Cursor extends Disposable implements ICursors {
600579 }
601580 const closeChar = m [ 1 ] ;
602581
603- const autoClosingPairsCandidates = this . context . config . autoClosingPairsClose2 . get ( closeChar ) ;
582+ const autoClosingPairsCandidates = this . context . cursorConfig . autoClosingPairsClose2 . get ( closeChar ) ;
604583 if ( ! autoClosingPairsCandidates || autoClosingPairsCandidates . length !== 1 ) {
605584 return null ;
606585 }
@@ -661,7 +640,7 @@ export class Cursor extends Disposable implements ICursors {
661640 }
662641
663642 private _executeEdit ( callback : ( ) => void , eventsCollector : ViewEventsCollector , source : string | null | undefined , cursorChangeReason : CursorChangeReason = CursorChangeReason . NotSet ) : void {
664- if ( this . _configuration . options . get ( EditorOption . readOnly ) ) {
643+ if ( this . context . cursorConfig . readOnly ) {
665644 // we cannot edit when read only...
666645 this . _onDidAttemptReadOnlyEdit . fire ( undefined ) ;
667646 return ;
@@ -697,7 +676,7 @@ export class Cursor extends Disposable implements ICursors {
697676 if ( ! this . _isDoingComposition && source === 'keyboard' ) {
698677 // composition finishes, let's check if we need to auto complete if necessary.
699678 const autoClosedCharacters = AutoClosedAction . getAllAutoClosedCharacters ( this . _autoClosedActions ) ;
700- this . _executeEditOperation ( TypeOperations . compositionEndWithInterceptors ( this . _prevEditOperationType , this . context . config , this . context . model , this . _selectionsWhenCompositionStarted , this . getSelections ( ) , autoClosedCharacters ) ) ;
679+ this . _executeEditOperation ( TypeOperations . compositionEndWithInterceptors ( this . _prevEditOperationType , this . context . cursorConfig , this . _model , this . _selectionsWhenCompositionStarted , this . getSelections ( ) , autoClosedCharacters ) ) ;
701680 this . _selectionsWhenCompositionStarted = null ;
702681 }
703682 } , eventsCollector , source ) ;
@@ -716,32 +695,32 @@ export class Cursor extends Disposable implements ICursors {
716695
717696 // Here we must interpret each typed character individually
718697 const autoClosedCharacters = AutoClosedAction . getAllAutoClosedCharacters ( this . _autoClosedActions ) ;
719- this . _executeEditOperation ( TypeOperations . typeWithInterceptors ( this . _isDoingComposition , this . _prevEditOperationType , this . context . config , this . context . model , this . getSelections ( ) , autoClosedCharacters , chr ) ) ;
698+ this . _executeEditOperation ( TypeOperations . typeWithInterceptors ( this . _isDoingComposition , this . _prevEditOperationType , this . context . cursorConfig , this . _model , this . getSelections ( ) , autoClosedCharacters , chr ) ) ;
720699
721700 offset += charLength ;
722701 }
723702
724703 } else {
725- this . _executeEditOperation ( TypeOperations . typeWithoutInterceptors ( this . _prevEditOperationType , this . context . config , this . context . model , this . getSelections ( ) , text ) ) ;
704+ this . _executeEditOperation ( TypeOperations . typeWithoutInterceptors ( this . _prevEditOperationType , this . context . cursorConfig , this . _model , this . getSelections ( ) , text ) ) ;
726705 }
727706 } , eventsCollector , source ) ;
728707 }
729708
730709 public replacePreviousChar ( eventsCollector : ViewEventsCollector , text : string , replaceCharCnt : number , source ?: string | null | undefined ) : void {
731710 this . _executeEdit ( ( ) => {
732- this . _executeEditOperation ( TypeOperations . replacePreviousChar ( this . _prevEditOperationType , this . context . config , this . context . model , this . getSelections ( ) , text , replaceCharCnt ) ) ;
711+ this . _executeEditOperation ( TypeOperations . replacePreviousChar ( this . _prevEditOperationType , this . context . cursorConfig , this . _model , this . getSelections ( ) , text , replaceCharCnt ) ) ;
733712 } , eventsCollector , source ) ;
734713 }
735714
736715 public paste ( eventsCollector : ViewEventsCollector , text : string , pasteOnNewLine : boolean , multicursorText ?: string [ ] | null | undefined , source ?: string | null | undefined ) : void {
737716 this . _executeEdit ( ( ) => {
738- this . _executeEditOperation ( TypeOperations . paste ( this . context . config , this . context . model , this . getSelections ( ) , text , pasteOnNewLine , multicursorText || [ ] ) ) ;
717+ this . _executeEditOperation ( TypeOperations . paste ( this . context . cursorConfig , this . _model , this . getSelections ( ) , text , pasteOnNewLine , multicursorText || [ ] ) ) ;
739718 } , eventsCollector , source , CursorChangeReason . Paste ) ;
740719 }
741720
742721 public cut ( eventsCollector : ViewEventsCollector , source ?: string | null | undefined ) : void {
743722 this . _executeEdit ( ( ) => {
744- this . _executeEditOperation ( DeleteOperations . cut ( this . context . config , this . context . model , this . getSelections ( ) ) ) ;
723+ this . _executeEditOperation ( DeleteOperations . cut ( this . context . cursorConfig , this . _model , this . getSelections ( ) ) ) ;
745724 } , eventsCollector , source ) ;
746725 }
747726
0 commit comments