Skip to content

Commit a59cde5

Browse files
committed
1 parent 9f76dba commit a59cde5

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,14 @@ export class CursorMoveCommands {
404404
}
405405

406406
private static _moveLeft(viewModel: IViewModel, cursors: CursorState[], inSelectionMode: boolean, noOfColumns: number): PartialCursorState[] {
407+
const hasMultipleCursors = (cursors.length > 1);
407408
let result: PartialCursorState[] = [];
408409
for (let i = 0, len = cursors.length; i < len; i++) {
409410
const cursor = cursors[i];
410-
411+
const skipWrappingPointStop = hasMultipleCursors || !cursor.viewState.hasSelection();
411412
let newViewState = MoveOperations.moveLeft(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode, noOfColumns);
412413

413-
if (!cursor.viewState.hasSelection() && noOfColumns === 1 && newViewState.position.lineNumber !== cursor.viewState.position.lineNumber) {
414+
if (skipWrappingPointStop && noOfColumns === 1 && newViewState.position.lineNumber !== cursor.viewState.position.lineNumber) {
414415
// moved over to the previous view line
415416
const newViewModelPosition = viewModel.coordinatesConverter.convertViewPositionToModelPosition(newViewState.position);
416417
if (newViewModelPosition.lineNumber === cursor.modelState.position.lineNumber) {
@@ -436,12 +437,14 @@ export class CursorMoveCommands {
436437
}
437438

438439
private static _moveRight(viewModel: IViewModel, cursors: CursorState[], inSelectionMode: boolean, noOfColumns: number): PartialCursorState[] {
440+
const hasMultipleCursors = (cursors.length > 1);
439441
let result: PartialCursorState[] = [];
440442
for (let i = 0, len = cursors.length; i < len; i++) {
441443
const cursor = cursors[i];
444+
const skipWrappingPointStop = hasMultipleCursors || !cursor.viewState.hasSelection();
442445
let newViewState = MoveOperations.moveRight(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode, noOfColumns);
443446

444-
if (!cursor.viewState.hasSelection() && noOfColumns === 1 && newViewState.position.lineNumber !== cursor.viewState.position.lineNumber) {
447+
if (skipWrappingPointStop && noOfColumns === 1 && newViewState.position.lineNumber !== cursor.viewState.position.lineNumber) {
445448
// moved over to the next view line
446449
const newViewModelPosition = viewModel.coordinatesConverter.convertViewPositionToModelPosition(newViewState.position);
447450
if (newViewModelPosition.lineNumber === cursor.modelState.position.lineNumber) {

src/vs/editor/test/browser/controller/cursor.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,70 @@ suite('Editor Controller - Regression tests', () => {
22082208
});
22092209
});
22102210

2211+
test('issue #98320: Multi-Cursor, Wrap lines and cursorSelectRight ==> cursors out of sync', () => {
2212+
// a single model line => 4 view lines
2213+
withTestCodeEditor([
2214+
[
2215+
'lorem_ipsum-1993x11x13',
2216+
'dolor_sit_amet-1998x04x27',
2217+
'consectetur-2007x10x08',
2218+
'adipiscing-2012x07x27',
2219+
'elit-2015x02x27',
2220+
].join('\n')
2221+
], { wordWrap: 'wordWrapColumn', wordWrapColumn: 16 }, (editor, viewModel) => {
2222+
viewModel.setSelections('test', [
2223+
new Selection(1, 13, 1, 13),
2224+
new Selection(2, 16, 2, 16),
2225+
new Selection(3, 13, 3, 13),
2226+
new Selection(4, 12, 4, 12),
2227+
new Selection(5, 6, 5, 6),
2228+
]);
2229+
assertCursor(viewModel, [
2230+
new Selection(1, 13, 1, 13),
2231+
new Selection(2, 16, 2, 16),
2232+
new Selection(3, 13, 3, 13),
2233+
new Selection(4, 12, 4, 12),
2234+
new Selection(5, 6, 5, 6),
2235+
]);
2236+
2237+
moveRight(editor, viewModel, true);
2238+
assertCursor(viewModel, [
2239+
new Selection(1, 13, 1, 14),
2240+
new Selection(2, 16, 2, 17),
2241+
new Selection(3, 13, 3, 14),
2242+
new Selection(4, 12, 4, 13),
2243+
new Selection(5, 6, 5, 7),
2244+
]);
2245+
2246+
moveRight(editor, viewModel, true);
2247+
assertCursor(viewModel, [
2248+
new Selection(1, 13, 1, 15),
2249+
new Selection(2, 16, 2, 18),
2250+
new Selection(3, 13, 3, 15),
2251+
new Selection(4, 12, 4, 14),
2252+
new Selection(5, 6, 5, 8),
2253+
]);
2254+
2255+
moveRight(editor, viewModel, true);
2256+
assertCursor(viewModel, [
2257+
new Selection(1, 13, 1, 16),
2258+
new Selection(2, 16, 2, 19),
2259+
new Selection(3, 13, 3, 16),
2260+
new Selection(4, 12, 4, 15),
2261+
new Selection(5, 6, 5, 9),
2262+
]);
2263+
2264+
moveRight(editor, viewModel, true);
2265+
assertCursor(viewModel, [
2266+
new Selection(1, 13, 1, 17),
2267+
new Selection(2, 16, 2, 20),
2268+
new Selection(3, 13, 3, 17),
2269+
new Selection(4, 12, 4, 16),
2270+
new Selection(5, 6, 5, 10),
2271+
]);
2272+
});
2273+
});
2274+
22112275
test('issue #41573 - delete across multiple lines does not shrink the selection when word wraps', () => {
22122276
withTestCodeEditor([
22132277
'Authorization: \'Bearer pHKRfCTFSnGxs6akKlb9ddIXcca0sIUSZJutPHYqz7vEeHdMTMh0SGN0IGU3a0n59DXjTLRsj5EJ2u33qLNIFi9fk5XF8pK39PndLYUZhPt4QvHGLScgSkK0L4gwzkzMloTQPpKhqiikiIOvyNNSpd2o8j29NnOmdTUOKi9DVt74PD2ohKxyOrWZ6oZprTkb3eKajcpnS0LABKfaw2rmv4\','

0 commit comments

Comments
 (0)