未验证 提交 5b28babf 编写于 作者: A Alex Dima

Fixes #96809: Add sticky argument and have it be false by default

上级 f4287e67
......@@ -958,7 +958,7 @@ export namespace CoreNavigationCommands {
viewModel.setCursorStates(
args.source,
CursorChangeReason.Explicit,
CursorMoveCommands.moveToEndOfLine(viewModel, viewModel.getCursorStates(), this._inSelectionMode)
CursorMoveCommands.moveToEndOfLine(viewModel, viewModel.getCursorStates(), this._inSelectionMode, args.sticky || false)
);
viewModel.revealPrimaryCursor(args.source, true);
}
......@@ -969,10 +969,27 @@ export namespace CoreNavigationCommands {
id: 'cursorEnd',
precondition: undefined,
kbOpts: {
args: { sticky: false },
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.textInputFocus,
primary: KeyCode.End,
mac: { primary: KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyCode.RightArrow] }
},
description: {
description: `Go to End`,
args: [{
name: 'args',
schema: {
type: 'object',
properties: {
'sticky': {
description: nls.localize('stickydesc', "Stick to the end even when going to longer lines"),
type: 'boolean',
default: false
}
}
}
}]
}
}));
......@@ -981,10 +998,27 @@ export namespace CoreNavigationCommands {
id: 'cursorEndSelect',
precondition: undefined,
kbOpts: {
args: { sticky: false },
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.textInputFocus,
primary: KeyMod.Shift | KeyCode.End,
mac: { primary: KeyMod.Shift | KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow] }
},
description: {
description: `Select to End`,
args: [{
name: 'args',
schema: {
type: 'object',
properties: {
'sticky': {
description: nls.localize('stickydesc', "Stick to the end even when going to longer lines"),
type: 'boolean',
default: false
}
}
}
}]
}
}));
......
......@@ -43,6 +43,10 @@ export interface IDiffEditorContributionDescription {
export interface ICommandKeybindingsOptions extends IKeybindings {
kbExpr?: ContextKeyExpression | null;
weight: number;
/**
* the default keybinding arguments
*/
args?: any;
}
export interface ICommandMenuOptions {
menuId: MenuId;
......@@ -96,6 +100,7 @@ export abstract class Command {
id: this.id,
handler: (accessor, args) => this.runCommand(accessor, args),
weight: this._kbOpts.weight,
args: this._kbOpts.args,
when: kbWhen,
primary: this._kbOpts.primary,
secondary: this._kbOpts.secondary,
......
......@@ -80,17 +80,17 @@ export class CursorMoveCommands {
);
}
public static moveToEndOfLine(viewModel: IViewModel, cursors: CursorState[], inSelectionMode: boolean): PartialCursorState[] {
public static moveToEndOfLine(viewModel: IViewModel, cursors: CursorState[], inSelectionMode: boolean, sticky: boolean): PartialCursorState[] {
let result: PartialCursorState[] = [];
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[i] = this._moveToLineEnd(viewModel, cursor, inSelectionMode);
result[i] = this._moveToLineEnd(viewModel, cursor, inSelectionMode, sticky);
}
return result;
}
private static _moveToLineEnd(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean): PartialCursorState {
private static _moveToLineEnd(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean, sticky: boolean): PartialCursorState {
const viewStatePosition = cursor.viewState.position;
const viewModelMaxColumn = viewModel.getLineMaxColumn(viewStatePosition.lineNumber);
const isEndOfViewLine = viewStatePosition.column === viewModelMaxColumn;
......@@ -100,21 +100,21 @@ export class CursorMoveCommands {
const isEndLineOfWrappedLine = viewModelMaxColumn - viewStatePosition.column === modelMaxColumn - modelStatePosition.column;
if (isEndOfViewLine || isEndLineOfWrappedLine) {
return this._moveToLineEndByModel(viewModel, cursor, inSelectionMode);
return this._moveToLineEndByModel(viewModel, cursor, inSelectionMode, sticky);
} else {
return this._moveToLineEndByView(viewModel, cursor, inSelectionMode);
return this._moveToLineEndByView(viewModel, cursor, inSelectionMode, sticky);
}
}
private static _moveToLineEndByView(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean): PartialCursorState {
private static _moveToLineEndByView(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean, sticky: boolean): PartialCursorState {
return CursorState.fromViewState(
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode)
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode, sticky)
);
}
private static _moveToLineEndByModel(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean): PartialCursorState {
private static _moveToLineEndByModel(viewModel: IViewModel, cursor: CursorState, inSelectionMode: boolean, sticky: boolean): PartialCursorState {
return CursorState.fromModelState(
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel.model, cursor.modelState, inSelectionMode)
MoveOperations.moveToEndOfLine(viewModel.cursorConfig, viewModel.model, cursor.modelState, inSelectionMode, sticky)
);
}
......
......@@ -222,10 +222,10 @@ export class MoveOperations {
return cursor.move(inSelectionMode, lineNumber, column, 0);
}
public static moveToEndOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {
public static moveToEndOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, sticky: boolean): SingleCursorState {
let lineNumber = cursor.position.lineNumber;
let maxColumn = model.getLineMaxColumn(lineNumber);
return cursor.move(inSelectionMode, lineNumber, maxColumn, Constants.MAX_SAFE_SMALL_INTEGER - maxColumn);
return cursor.move(inSelectionMode, lineNumber, maxColumn, sticky ? Constants.MAX_SAFE_SMALL_INTEGER - maxColumn : 0);
}
public static moveToBeginningOfBuffer(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册