Skip to content

Commit 5b28bab

Browse files
committed
Fixes microsoft#96809: Add sticky argument and have it be false by default
1 parent f4287e6 commit 5b28bab

4 files changed

Lines changed: 51 additions & 12 deletions

File tree

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ export namespace CoreNavigationCommands {
958958
viewModel.setCursorStates(
959959
args.source,
960960
CursorChangeReason.Explicit,
961-
CursorMoveCommands.moveToEndOfLine(viewModel, viewModel.getCursorStates(), this._inSelectionMode)
961+
CursorMoveCommands.moveToEndOfLine(viewModel, viewModel.getCursorStates(), this._inSelectionMode, args.sticky || false)
962962
);
963963
viewModel.revealPrimaryCursor(args.source, true);
964964
}
@@ -969,10 +969,27 @@ export namespace CoreNavigationCommands {
969969
id: 'cursorEnd',
970970
precondition: undefined,
971971
kbOpts: {
972+
args: { sticky: false },
972973
weight: CORE_WEIGHT,
973974
kbExpr: EditorContextKeys.textInputFocus,
974975
primary: KeyCode.End,
975976
mac: { primary: KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyCode.RightArrow] }
977+
},
978+
description: {
979+
description: `Go to End`,
980+
args: [{
981+
name: 'args',
982+
schema: {
983+
type: 'object',
984+
properties: {
985+
'sticky': {
986+
description: nls.localize('stickydesc', "Stick to the end even when going to longer lines"),
987+
type: 'boolean',
988+
default: false
989+
}
990+
}
991+
}
992+
}]
976993
}
977994
}));
978995

@@ -981,10 +998,27 @@ export namespace CoreNavigationCommands {
981998
id: 'cursorEndSelect',
982999
precondition: undefined,
9831000
kbOpts: {
1001+
args: { sticky: false },
9841002
weight: CORE_WEIGHT,
9851003
kbExpr: EditorContextKeys.textInputFocus,
9861004
primary: KeyMod.Shift | KeyCode.End,
9871005
mac: { primary: KeyMod.Shift | KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow] }
1006+
},
1007+
description: {
1008+
description: `Select to End`,
1009+
args: [{
1010+
name: 'args',
1011+
schema: {
1012+
type: 'object',
1013+
properties: {
1014+
'sticky': {
1015+
description: nls.localize('stickydesc', "Stick to the end even when going to longer lines"),
1016+
type: 'boolean',
1017+
default: false
1018+
}
1019+
}
1020+
}
1021+
}]
9881022
}
9891023
}));
9901024

src/vs/editor/browser/editorExtensions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export interface IDiffEditorContributionDescription {
4343
export interface ICommandKeybindingsOptions extends IKeybindings {
4444
kbExpr?: ContextKeyExpression | null;
4545
weight: number;
46+
/**
47+
* the default keybinding arguments
48+
*/
49+
args?: any;
4650
}
4751
export interface ICommandMenuOptions {
4852
menuId: MenuId;
@@ -96,6 +100,7 @@ export abstract class Command {
96100
id: this.id,
97101
handler: (accessor, args) => this.runCommand(accessor, args),
98102
weight: this._kbOpts.weight,
103+
args: this._kbOpts.args,
99104
when: kbWhen,
100105
primary: this._kbOpts.primary,
101106
secondary: this._kbOpts.secondary,

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ export class CursorMoveCommands {
8080
);
8181
}
8282

83-
public static moveToEndOfLine(viewModel: IViewModel, cursors: CursorState[], inSelectionMode: boolean): PartialCursorState[] {
83+
public static moveToEndOfLine(viewModel: IViewModel, cursors: CursorState[], inSelectionMode: boolean, sticky: boolean): PartialCursorState[] {
8484
let result: PartialCursorState[] = [];
8585
for (let i = 0, len = cursors.length; i < len; i++) {
8686
const cursor = cursors[i];
87-
result[i] = this._moveToLineEnd(viewModel, cursor, inSelectionMode);
87+
result[i] = this._moveToLineEnd(viewModel, cursor, inSelectionMode, sticky);
8888
}
8989

9090
return result;
9191
}
9292

93-
private static _moveToLineEnd(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean): PartialCursorState {
93+
private static _moveToLineEnd(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean, sticky: boolean): PartialCursorState {
9494
const viewStatePosition = cursor.viewState.position;
9595
const viewModelMaxColumn = viewModel.getLineMaxColumn(viewStatePosition.lineNumber);
9696
const isEndOfViewLine = viewStatePosition.column === viewModelMaxColumn;
@@ -100,21 +100,21 @@ export class CursorMoveCommands {
100100
const isEndLineOfWrappedLine = viewModelMaxColumn - viewStatePosition.column === modelMaxColumn - modelStatePosition.column;
101101

102102
if (isEndOfViewLine || isEndLineOfWrappedLine) {
103-
return this._moveToLineEndByModel(viewModel, cursor, inSelectionMode);
103+
return this._moveToLineEndByModel(viewModel, cursor, inSelectionMode, sticky);
104104
} else {
105-
return this._moveToLineEndByView(viewModel, cursor, inSelectionMode);
105+
return this._moveToLineEndByView(viewModel, cursor, inSelectionMode, sticky);
106106
}
107107
}
108108

109-
private static _moveToLineEndByView(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean): PartialCursorState {
109+
private static _moveToLineEndByView(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean, sticky: boolean): PartialCursorState {
110110
return CursorState.fromViewState(
111-
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode)
111+
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode, sticky)
112112
);
113113
}
114114

115-
private static _moveToLineEndByModel(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean): PartialCursorState {
115+
private static _moveToLineEndByModel(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean, sticky: boolean): PartialCursorState {
116116
return CursorState.fromModelState(
117-
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel.model, cursor.modelState, inSelectionMode)
117+
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel.model, cursor.modelState, inSelectionMode, sticky)
118118
);
119119
}
120120

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ export class MoveOperations {
222222
return cursor.move(inSelectionMode, lineNumber, column, 0);
223223
}
224224

225-
public static moveToEndOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {
225+
public static moveToEndOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, sticky: boolean): SingleCursorState {
226226
let lineNumber = cursor.position.lineNumber;
227227
let maxColumn = model.getLineMaxColumn(lineNumber);
228-
return cursor.move(inSelectionMode, lineNumber, maxColumn, Constants.MAX_SAFE_SMALL_INTEGER - maxColumn);
228+
return cursor.move(inSelectionMode, lineNumber, maxColumn, sticky ? Constants.MAX_SAFE_SMALL_INTEGER - maxColumn : 0);
229229
}
230230

231231
public static moveToBeginningOfBuffer(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {

0 commit comments

Comments
 (0)