Skip to content

Commit 115fd0b

Browse files
committed
Remove editable range code (fixes microsoft#38633)
1 parent ff9c9e5 commit 115fd0b

15 files changed

Lines changed: 30 additions & 306 deletions

File tree

src/vs/editor/browser/controller/coreCommands.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,7 @@ export namespace CoreNavigationCommands {
455455
cursors.setStates(
456456
source,
457457
CursorChangeReason.Explicit,
458-
CursorState.ensureInEditableRange(
459-
cursors.context,
460-
CursorMoveCommands.move(cursors.context, cursors.getAll(), args)
461-
)
458+
CursorMoveCommands.move(cursors.context, cursors.getAll(), args)
462459
);
463460
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
464461
}
@@ -707,7 +704,7 @@ export namespace CoreNavigationCommands {
707704
public runCoreEditorCommand(cursors: ICursors, args: any): void {
708705
const context = cursors.context;
709706

710-
if (context.config.readOnly || context.model.hasEditableRange()) {
707+
if (context.config.readOnly) {
711708
return;
712709
}
713710

@@ -772,7 +769,7 @@ export namespace CoreNavigationCommands {
772769
public runCoreEditorCommand(cursors: ICursors, args: any): void {
773770
const context = cursors.context;
774771

775-
if (context.config.readOnly || context.model.hasEditableRange()) {
772+
if (context.config.readOnly) {
776773
return;
777774
}
778775

@@ -804,10 +801,7 @@ export namespace CoreNavigationCommands {
804801
cursors.setStates(
805802
args.source,
806803
CursorChangeReason.Explicit,
807-
CursorState.ensureInEditableRange(
808-
cursors.context,
809-
CursorMoveCommands.moveToBeginningOfLine(cursors.context, cursors.getAll(), this._inSelectionMode)
810-
)
804+
CursorMoveCommands.moveToBeginningOfLine(cursors.context, cursors.getAll(), this._inSelectionMode)
811805
);
812806
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
813807
}
@@ -856,10 +850,7 @@ export namespace CoreNavigationCommands {
856850
cursors.setStates(
857851
args.source,
858852
CursorChangeReason.Explicit,
859-
CursorState.ensureInEditableRange(
860-
cursors.context,
861-
this._exec(cursors.context, cursors.getAll())
862-
)
853+
this._exec(cursors.context, cursors.getAll())
863854
);
864855
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
865856
}
@@ -889,10 +880,7 @@ export namespace CoreNavigationCommands {
889880
cursors.setStates(
890881
args.source,
891882
CursorChangeReason.Explicit,
892-
CursorState.ensureInEditableRange(
893-
cursors.context,
894-
CursorMoveCommands.moveToEndOfLine(cursors.context, cursors.getAll(), this._inSelectionMode)
895-
)
883+
CursorMoveCommands.moveToEndOfLine(cursors.context, cursors.getAll(), this._inSelectionMode)
896884
);
897885
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
898886
}
@@ -941,10 +929,7 @@ export namespace CoreNavigationCommands {
941929
cursors.setStates(
942930
args.source,
943931
CursorChangeReason.Explicit,
944-
CursorState.ensureInEditableRange(
945-
cursors.context,
946-
this._exec(cursors.context, cursors.getAll())
947-
)
932+
this._exec(cursors.context, cursors.getAll())
948933
);
949934
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
950935
}
@@ -975,10 +960,7 @@ export namespace CoreNavigationCommands {
975960
cursors.setStates(
976961
args.source,
977962
CursorChangeReason.Explicit,
978-
CursorState.ensureInEditableRange(
979-
cursors.context,
980-
CursorMoveCommands.moveToBeginningOfBuffer(cursors.context, cursors.getAll(), this._inSelectionMode)
981-
)
963+
CursorMoveCommands.moveToBeginningOfBuffer(cursors.context, cursors.getAll(), this._inSelectionMode)
982964
);
983965
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
984966
}
@@ -1022,10 +1004,7 @@ export namespace CoreNavigationCommands {
10221004
cursors.setStates(
10231005
args.source,
10241006
CursorChangeReason.Explicit,
1025-
CursorState.ensureInEditableRange(
1026-
cursors.context,
1027-
CursorMoveCommands.moveToEndOfBuffer(cursors.context, cursors.getAll(), this._inSelectionMode)
1028-
)
1007+
CursorMoveCommands.moveToEndOfBuffer(cursors.context, cursors.getAll(), this._inSelectionMode)
10291008
);
10301009
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
10311010
}
@@ -1272,7 +1251,7 @@ export namespace CoreNavigationCommands {
12721251

12731252
public runCoreEditorCommand(cursors: ICursors, args: any): void {
12741253
const context = cursors.context;
1275-
if (context.config.readOnly || context.model.hasEditableRange()) {
1254+
if (context.config.readOnly) {
12761255
return;
12771256
}
12781257

@@ -1335,7 +1314,7 @@ export namespace CoreNavigationCommands {
13351314
public runCoreEditorCommand(cursors: ICursors, args: any): void {
13361315
const context = cursors.context;
13371316

1338-
if (context.config.readOnly || context.model.hasEditableRange()) {
1317+
if (context.config.readOnly) {
13391318
return;
13401319
}
13411320

@@ -1383,10 +1362,7 @@ export namespace CoreNavigationCommands {
13831362
cursors.setStates(
13841363
args.source,
13851364
CursorChangeReason.Explicit,
1386-
CursorState.ensureInEditableRange(
1387-
cursors.context,
1388-
CursorMoveCommands.expandLineSelection(cursors.context, cursors.getAll())
1389-
)
1365+
CursorMoveCommands.expandLineSelection(cursors.context, cursors.getAll())
13901366
);
13911367
cursors.reveal(true, RevealTarget.Primary, editorCommon.ScrollType.Smooth);
13921368
}

src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
1818
private _lineHeight: number;
1919
private _renderLineHighlight: 'none' | 'gutter' | 'line' | 'all';
2020
private _selectionIsEmpty: boolean;
21-
private _primaryCursorIsInEditableRange: boolean;
2221
private _primaryCursorLineNumber: number;
2322
private _scrollWidth: number;
2423
private _contentWidth: number;
@@ -30,7 +29,6 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
3029
this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight;
3130

3231
this._selectionIsEmpty = true;
33-
this._primaryCursorIsInEditableRange = true;
3432
this._primaryCursorLineNumber = 1;
3533
this._scrollWidth = 0;
3634
this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth;
@@ -61,11 +59,6 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
6159
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
6260
let hasChanged = false;
6361

64-
if (this._primaryCursorIsInEditableRange !== e.isInEditableRange) {
65-
this._primaryCursorIsInEditableRange = e.isInEditableRange;
66-
hasChanged = true;
67-
}
68-
6962
const primaryCursorLineNumber = e.selections[0].positionLineNumber;
7063
if (this._primaryCursorLineNumber !== primaryCursorLineNumber) {
7164
this._primaryCursorLineNumber = primaryCursorLineNumber;
@@ -127,14 +120,12 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
127120
return (
128121
(this._renderLineHighlight === 'line' || this._renderLineHighlight === 'all')
129122
&& this._selectionIsEmpty
130-
&& this._primaryCursorIsInEditableRange
131123
);
132124
}
133125

134126
private _willRenderMarginCurrentLine(): boolean {
135127
return (
136128
(this._renderLineHighlight === 'gutter' || this._renderLineHighlight === 'all')
137-
&& this._primaryCursorIsInEditableRange
138129
);
139130
}
140131
}

src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay {
1818
private _lineHeight: number;
1919
private _renderLineHighlight: 'none' | 'gutter' | 'line' | 'all';
2020
private _selectionIsEmpty: boolean;
21-
private _primaryCursorIsInEditableRange: boolean;
2221
private _primaryCursorLineNumber: number;
2322
private _contentLeft: number;
2423

@@ -29,7 +28,6 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay {
2928
this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight;
3029

3130
this._selectionIsEmpty = true;
32-
this._primaryCursorIsInEditableRange = true;
3331
this._primaryCursorLineNumber = 1;
3432
this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft;
3533

@@ -59,11 +57,6 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay {
5957
public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
6058
let hasChanged = false;
6159

62-
if (this._primaryCursorIsInEditableRange !== e.isInEditableRange) {
63-
this._primaryCursorIsInEditableRange = e.isInEditableRange;
64-
hasChanged = true;
65-
}
66-
6760
const primaryCursorLineNumber = e.selections[0].positionLineNumber;
6861
if (this._primaryCursorLineNumber !== primaryCursorLineNumber) {
6962
this._primaryCursorLineNumber = primaryCursorLineNumber;
@@ -120,15 +113,13 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay {
120113
private _shouldShowCurrentLine(): boolean {
121114
return (
122115
(this._renderLineHighlight === 'gutter' || this._renderLineHighlight === 'all')
123-
&& this._primaryCursorIsInEditableRange
124116
);
125117
}
126118

127119
private _willRenderContentCurrentLine(): boolean {
128120
return (
129121
(this._renderLineHighlight === 'line' || this._renderLineHighlight === 'all')
130122
&& this._selectionIsEmpty
131-
&& this._primaryCursorIsInEditableRange
132123
);
133124
}
134125
}

src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export class ViewCursor {
4848
private _isVisible: boolean;
4949

5050
private _position: Position;
51-
private _isInEditableRange: boolean;
5251

5352
private _lastRenderedContent: string;
5453
private _renderData: ViewCursorRenderData;
@@ -77,7 +76,6 @@ export class ViewCursor {
7776
this._domNode.setDisplay('none');
7877

7978
this.updatePosition(new Position(1, 1));
80-
this._isInEditableRange = true;
8179

8280
this._lastRenderedContent = '';
8381
this._renderData = null;
@@ -87,10 +85,6 @@ export class ViewCursor {
8785
return this._domNode;
8886
}
8987

90-
public getIsInEditableRange(): boolean {
91-
return this._isInEditableRange;
92-
}
93-
9488
public getPosition(): Position {
9589
return this._position;
9690
}
@@ -123,9 +117,8 @@ export class ViewCursor {
123117
return true;
124118
}
125119

126-
public onCursorPositionChanged(position: Position, isInEditableRange: boolean): boolean {
120+
public onCursorPositionChanged(position: Position): boolean {
127121
this.updatePosition(position);
128-
this._isInEditableRange = isInEditableRange;
129122
return true;
130123
}
131124

src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export class ViewCursors extends ViewPart {
101101
}
102102
return true;
103103
}
104-
private _onCursorPositionChanged(position: Position, secondaryPositions: Position[], isInEditableRange: boolean): void {
105-
this._primaryCursor.onCursorPositionChanged(position, isInEditableRange);
104+
private _onCursorPositionChanged(position: Position, secondaryPositions: Position[]): void {
105+
this._primaryCursor.onCursorPositionChanged(position);
106106
this._updateBlinking();
107107

108108
if (this._secondaryCursors.length < secondaryPositions.length) {
@@ -123,7 +123,7 @@ export class ViewCursors extends ViewPart {
123123
}
124124

125125
for (let i = 0; i < secondaryPositions.length; i++) {
126-
this._secondaryCursors[i].onCursorPositionChanged(secondaryPositions[i], isInEditableRange);
126+
this._secondaryCursors[i].onCursorPositionChanged(secondaryPositions[i]);
127127
}
128128

129129
}
@@ -132,7 +132,7 @@ export class ViewCursors extends ViewPart {
132132
for (let i = 0, len = e.selections.length; i < len; i++) {
133133
positions[i] = e.selections[i].getPosition();
134134
}
135-
this._onCursorPositionChanged(positions[0], positions.slice(1), e.isInEditableRange);
135+
this._onCursorPositionChanged(positions[0], positions.slice(1));
136136

137137
const selectionIsEmpty = e.selections[0].isEmpty();
138138
if (this._selectionIsEmpty !== selectionIsEmpty) {
@@ -198,7 +198,7 @@ export class ViewCursors extends ViewPart {
198198
if (!this._editorHasFocus) {
199199
return TextEditorCursorBlinkingStyle.Hidden;
200200
}
201-
if (this._readOnly || !this._primaryCursor.getIsInEditableRange()) {
201+
if (this._readOnly) {
202202
return TextEditorCursorBlinkingStyle.Solid;
203203
}
204204
return this._cursorBlinking;

src/vs/editor/common/controller/cursor.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -369,20 +369,11 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
369369
return false;
370370
}
371371

372-
373-
let isInEditableRange: boolean = true;
374-
if (this._model.hasEditableRange()) {
375-
const editableRange = this._model.getEditableRange();
376-
if (!editableRange.containsPosition(newState.cursorState[0].modelState.position)) {
377-
isInEditableRange = false;
378-
}
379-
}
380-
381372
const selections = this._cursors.getSelections();
382373
const viewSelections = this._cursors.getViewSelections();
383374

384375
// Let the view get the event first.
385-
this._emit([new viewEvents.ViewCursorStateChangedEvent(viewSelections, isInEditableRange)]);
376+
this._emit([new viewEvents.ViewCursorStateChangedEvent(viewSelections)]);
386377

387378
// Only after the view has been notified, let the rest of the world know...
388379
if (!oldState
@@ -601,17 +592,6 @@ class CommandExecutor {
601592

602593
const rawOperations = commandsData.operations;
603594

604-
const editableRange = ctx.model.getEditableRange();
605-
const editableRangeStart = editableRange.getStartPosition();
606-
const editableRangeEnd = editableRange.getEndPosition();
607-
for (let i = 0, len = rawOperations.length; i < len; i++) {
608-
const operationRange = rawOperations[i].range;
609-
if (!editableRangeStart.isBeforeOrEqual(operationRange.getStartPosition()) || !operationRange.getEndPosition().isBeforeOrEqual(editableRangeEnd)) {
610-
// These commands are outside of the editable range
611-
return null;
612-
}
613-
}
614-
615595
const loserCursorsMap = this._getLoserCursorMap(rawOperations);
616596
if (loserCursorsMap.hasOwnProperty('0')) {
617597
// These commands are very messed up

src/vs/editor/common/controller/cursorCommon.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -381,50 +381,6 @@ export class CursorState {
381381
return states;
382382
}
383383

384-
public static ensureInEditableRange(context: CursorContext, states: CursorState[]): CursorState[] {
385-
const model = context.model;
386-
if (!model.hasEditableRange()) {
387-
return states;
388-
}
389-
390-
const modelEditableRange = model.getEditableRange();
391-
const viewEditableRange = context.convertModelRangeToViewRange(modelEditableRange);
392-
393-
let result: CursorState[] = [];
394-
for (let i = 0, len = states.length; i < len; i++) {
395-
const state = states[i];
396-
397-
if (state.modelState) {
398-
const newModelState = CursorState._ensureInEditableRange(state.modelState, modelEditableRange);
399-
result[i] = newModelState ? CursorState.fromModelState(newModelState) : state;
400-
} else {
401-
const newViewState = CursorState._ensureInEditableRange(state.viewState, viewEditableRange);
402-
result[i] = newViewState ? CursorState.fromViewState(newViewState) : state;
403-
}
404-
}
405-
return result;
406-
}
407-
408-
private static _ensureInEditableRange(state: SingleCursorState, editableRange: Range): SingleCursorState {
409-
const position = state.position;
410-
411-
if (position.lineNumber < editableRange.startLineNumber || (position.lineNumber === editableRange.startLineNumber && position.column < editableRange.startColumn)) {
412-
return new SingleCursorState(
413-
state.selectionStart, state.selectionStartLeftoverVisibleColumns,
414-
new Position(editableRange.startLineNumber, editableRange.startColumn), 0
415-
);
416-
}
417-
418-
if (position.lineNumber > editableRange.endLineNumber || (position.lineNumber === editableRange.endLineNumber && position.column > editableRange.endColumn)) {
419-
return new SingleCursorState(
420-
state.selectionStart, state.selectionStartLeftoverVisibleColumns,
421-
new Position(editableRange.endLineNumber, editableRange.endColumn), 0
422-
);
423-
}
424-
425-
return null;
426-
}
427-
428384
readonly modelState: SingleCursorState;
429385
readonly viewState: SingleCursorState;
430386

0 commit comments

Comments
 (0)