Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #4375 - Multiple Cursors now go to the next logical line #49318

Merged
merged 3 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 26 additions & 10 deletions src/vs/editor/common/controller/cursorMoveCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,38 @@ import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands

export class CursorMoveCommands {

public static addCursorDown(context: CursorContext, cursors: CursorState[]): CursorState[] {
public static addCursorDown(context: CursorContext, cursors: CursorState[], useLogicalLine: boolean): CursorState[] {
let result: CursorState[] = [], resultLen = 0;
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[resultLen++] = new CursorState(cursor.modelState, cursor.viewState);
result[resultLen++] = CursorState.fromViewState(MoveOperations.translateDown(context.config, context.viewModel, cursor.viewState));
if (useLogicalLine) {
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[resultLen++] = new CursorState(cursor.modelState, cursor.viewState);
result[resultLen++] = CursorState.fromModelState(MoveOperations.translateDown(context.config, context.model, cursor.modelState));
}
} else {
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[resultLen++] = new CursorState(cursor.modelState, cursor.viewState);
result[resultLen++] = CursorState.fromViewState(MoveOperations.translateDown(context.config, context.viewModel, cursor.viewState));
}
}
return result;
}

public static addCursorUp(context: CursorContext, cursors: CursorState[]): CursorState[] {
public static addCursorUp(context: CursorContext, cursors: CursorState[], useLogicalLine: boolean): CursorState[] {
let result: CursorState[] = [], resultLen = 0;
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[resultLen++] = new CursorState(cursor.modelState, cursor.viewState);
result[resultLen++] = CursorState.fromViewState(MoveOperations.translateUp(context.config, context.viewModel, cursor.viewState));
if (useLogicalLine) {
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[resultLen++] = new CursorState(cursor.modelState, cursor.viewState);
result[resultLen++] = CursorState.fromModelState(MoveOperations.translateUp(context.config, context.model, cursor.modelState));
}
} else {
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[resultLen++] = new CursorState(cursor.modelState, cursor.viewState);
result[resultLen++] = CursorState.fromViewState(MoveOperations.translateUp(context.config, context.viewModel, cursor.viewState));
}
}
return result;
}
Expand Down
8 changes: 6 additions & 2 deletions src/vs/editor/contrib/multicursor/multicursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { INewFindReplaceState, FindOptionOverride } from 'vs/editor/contrib/find
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';

export class InsertCursorAbove extends EditorAction {

constructor() {
super({
id: 'editor.action.insertCursorAbove',
Expand All @@ -45,6 +46,7 @@ export class InsertCursorAbove extends EditorAction {
}

public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
const useLogicalLine = (args && args.logicalLine === true);
const cursors = editor._getCursors();
const context = cursors.context;

Expand All @@ -56,13 +58,14 @@ export class InsertCursorAbove extends EditorAction {
cursors.setStates(
args.source,
CursorChangeReason.Explicit,
CursorMoveCommands.addCursorUp(context, cursors.getAll())
CursorMoveCommands.addCursorUp(context, cursors.getAll(), useLogicalLine)
);
cursors.reveal(true, RevealTarget.TopMost, ScrollType.Smooth);
}
}

export class InsertCursorBelow extends EditorAction {

constructor() {
super({
id: 'editor.action.insertCursorBelow',
Expand All @@ -81,6 +84,7 @@ export class InsertCursorBelow extends EditorAction {
}

public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
const useLogicalLine = (args && args.logicalLine === true);
const cursors = editor._getCursors();
const context = cursors.context;

Expand All @@ -92,7 +96,7 @@ export class InsertCursorBelow extends EditorAction {
cursors.setStates(
args.source,
CursorChangeReason.Explicit,
CursorMoveCommands.addCursorDown(context, cursors.getAll())
CursorMoveCommands.addCursorDown(context, cursors.getAll(), useLogicalLine)
);
cursors.reveal(true, RevealTarget.BottomMost, ScrollType.Smooth);
}
Expand Down