Skip to content

Commit 7e99bd3

Browse files
committed
Make IEditor.setSelections take a readonly array
This array cannot be modified after it is passed to the editor to update the selections
1 parent f2b1bb2 commit 7e99bd3

7 files changed

Lines changed: 8 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
737737
);
738738
}
739739

740-
public setSelections(ranges: ISelection[], source: string = 'api'): void {
740+
public setSelections(ranges: readonly ISelection[], source: string = 'api'): void {
741741
if (!this._modelData) {
742742
return;
743743
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
723723
this.modifiedEditor.setSelection(something);
724724
}
725725

726-
public setSelections(ranges: ISelection[]): void {
726+
public setSelections(ranges: readonly ISelection[]): void {
727727
this.modifiedEditor.setSelections(ranges);
728728
}
729729

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
424424
return this._cursors.getPrimaryCursor().modelState.position;
425425
}
426426

427-
public setSelections(source: string, selections: ISelection[]): void {
427+
public setSelections(source: string, selections: readonly ISelection[]): void {
428428
this.setStates(source, CursorChangeReason.NotSet, CursorState.fromModelSelections(selections));
429429
}
430430

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export class CursorState {
460460
return CursorState.fromModelState(modelState);
461461
}
462462

463-
public static fromModelSelections(modelSelections: ISelection[]): PartialModelCursorState[] {
463+
public static fromModelSelections(modelSelections: readonly ISelection[]): PartialModelCursorState[] {
464464
let states: PartialModelCursorState[] = [];
465465
for (let i = 0, len = modelSelections.length; i < len; i++) {
466466
states[i] = this.fromModelSelection(modelSelections[i]);

src/vs/editor/common/editorCommon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export interface IEditor {
389389
* Set the selections for all the cursors of the editor.
390390
* Cursors will be removed or added, as necessary.
391391
*/
392-
setSelections(selections: ISelection[]): void;
392+
setSelections(selections: readonly ISelection[]): void;
393393

394394
/**
395395
* Scroll vertically as necessary and reveal lines.

src/vs/editor/contrib/cursorUndo/cursorUndo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1414
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1515

1616
class CursorState {
17-
readonly selections: Selection[];
17+
readonly selections: readonly Selection[];
1818

19-
constructor(selections: Selection[]) {
19+
constructor(selections: readonly Selection[]) {
2020
this.selections = selections;
2121
}
2222

src/vs/monaco.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ declare namespace monaco.editor {
21522152
* Set the selections for all the cursors of the editor.
21532153
* Cursors will be removed or added, as necessary.
21542154
*/
2155-
setSelections(selections: ISelection[]): void;
2155+
setSelections(selections: readonly ISelection[]): void;
21562156
/**
21572157
* Scroll vertically as necessary and reveal lines.
21582158
*/

0 commit comments

Comments
 (0)