@@ -30,7 +30,7 @@ import { Cursor } from 'vs/editor/common/controller/cursor';
3030import { PartialCursorState , CursorState , IColumnSelectData , EditOperationType , CursorConfiguration } from 'vs/editor/common/controller/cursorCommon' ;
3131import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents' ;
3232import { IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout' ;
33- import { ViewModelEventDispatcher , OutgoingViewModelEvent , FocusChangedEvent , ScrollChangedEvent , ViewZonesChangedEvent , ViewModelEventsCollector } from 'vs/editor/common/viewModel/viewModelEventDispatcher' ;
33+ import { ViewModelEventDispatcher , OutgoingViewModelEvent , FocusChangedEvent , ScrollChangedEvent , ViewZonesChangedEvent , ViewModelEventsCollector , ReadOnlyEditAttemptEvent } from 'vs/editor/common/viewModel/viewModelEventDispatcher' ;
3434import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler' ;
3535
3636const USE_IDENTITY_LINES_COLLECTION = true ;
@@ -52,7 +52,7 @@ export class ViewModel extends Disposable implements IViewModel {
5252 private readonly lines : IViewModelLinesCollection ;
5353 public readonly coordinatesConverter : ICoordinatesConverter ;
5454 public readonly viewLayout : ViewLayout ;
55- public readonly cursor : Cursor ;
55+ private readonly cursor : Cursor ;
5656 private readonly decorations : ViewModelDecorations ;
5757
5858 constructor (
@@ -914,32 +914,42 @@ export class ViewModel extends Disposable implements IViewModel {
914914 this . _withViewEventsCollector ( eventsCollector => this . cursor . restoreState ( eventsCollector , states ) ) ;
915915 }
916916
917+ private _executeCursorEdit ( callback : ( eventsCollector : ViewModelEventsCollector ) => void ) : void {
918+ if ( this . cursor . context . cursorConfig . readOnly ) {
919+ // we cannot edit when read only...
920+ this . _eventDispatcher . emitOutgoingEvent ( new ReadOnlyEditAttemptEvent ( ) ) ;
921+ return ;
922+ }
923+ this . _withViewEventsCollector ( callback ) ;
924+ }
917925 public executeEdits ( source : string | null | undefined , edits : IIdentifiedSingleEditOperation [ ] , cursorStateComputer : ICursorStateComputer ) : void {
918- this . _withViewEventsCollector ( eventsCollector => this . cursor . executeEdits ( eventsCollector , source , edits , cursorStateComputer ) ) ;
926+ this . _executeCursorEdit ( eventsCollector => this . cursor . executeEdits ( eventsCollector , source , edits , cursorStateComputer ) ) ;
919927 }
920928 public startComposition ( ) : void {
921- this . _withViewEventsCollector ( eventsCollector => this . cursor . startComposition ( eventsCollector ) ) ;
929+ this . cursor . setIsDoingComposition ( true ) ;
930+ this . _executeCursorEdit ( eventsCollector => this . cursor . startComposition ( eventsCollector ) ) ;
922931 }
923932 public endComposition ( source ?: string | null | undefined ) : void {
924- this . _withViewEventsCollector ( eventsCollector => this . cursor . endComposition ( eventsCollector , source ) ) ;
933+ this . cursor . setIsDoingComposition ( false ) ;
934+ this . _executeCursorEdit ( eventsCollector => this . cursor . endComposition ( eventsCollector , source ) ) ;
925935 }
926936 public type ( text : string , source ?: string | null | undefined ) : void {
927- this . _withViewEventsCollector ( eventsCollector => this . cursor . type ( eventsCollector , text , source ) ) ;
937+ this . _executeCursorEdit ( eventsCollector => this . cursor . type ( eventsCollector , text , source ) ) ;
928938 }
929939 public replacePreviousChar ( text : string , replaceCharCnt : number , source ?: string | null | undefined ) : void {
930- this . _withViewEventsCollector ( eventsCollector => this . cursor . replacePreviousChar ( eventsCollector , text , replaceCharCnt , source ) ) ;
940+ this . _executeCursorEdit ( eventsCollector => this . cursor . replacePreviousChar ( eventsCollector , text , replaceCharCnt , source ) ) ;
931941 }
932942 public paste ( text : string , pasteOnNewLine : boolean , multicursorText ?: string [ ] | null | undefined , source ?: string | null | undefined ) : void {
933- this . _withViewEventsCollector ( eventsCollector => this . cursor . paste ( eventsCollector , text , pasteOnNewLine , multicursorText , source ) ) ;
943+ this . _executeCursorEdit ( eventsCollector => this . cursor . paste ( eventsCollector , text , pasteOnNewLine , multicursorText , source ) ) ;
934944 }
935945 public cut ( source ?: string | null | undefined ) : void {
936- this . _withViewEventsCollector ( eventsCollector => this . cursor . cut ( eventsCollector , source ) ) ;
946+ this . _executeCursorEdit ( eventsCollector => this . cursor . cut ( eventsCollector , source ) ) ;
937947 }
938948 public executeCommand ( command : ICommand , source ?: string | null | undefined ) : void {
939- this . _withViewEventsCollector ( eventsCollector => this . cursor . executeCommand ( eventsCollector , command , source ) ) ;
949+ this . _executeCursorEdit ( eventsCollector => this . cursor . executeCommand ( eventsCollector , command , source ) ) ;
940950 }
941951 public executeCommands ( commands : ICommand [ ] , source ?: string | null | undefined ) : void {
942- this . _withViewEventsCollector ( eventsCollector => this . cursor . executeCommands ( eventsCollector , commands , source ) ) ;
952+ this . _executeCursorEdit ( eventsCollector => this . cursor . executeCommands ( eventsCollector , commands , source ) ) ;
943953 }
944954 public revealPrimaryCursor ( source : string | null | undefined , revealHorizontal : boolean ) : void {
945955 this . _withViewEventsCollector ( eventsCollector => this . cursor . revealPrimary ( eventsCollector , source , revealHorizontal , ScrollType . Smooth ) ) ;
0 commit comments