Skip to content

Commit

Permalink
Fixes #36740: wordWrap : Creates an extra step / character at the wra…
Browse files Browse the repository at this point in the history
…pping point
  • Loading branch information
alexdima committed Oct 24, 2017
1 parent 739f487 commit fa4c556
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/vs/editor/common/controller/cursorMoveCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,19 @@ export class CursorMoveCommands {
let result: CursorState[] = [];
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[i] = CursorState.fromViewState(MoveOperations.moveLeft(context.config, context.viewModel, cursor.viewState, inSelectionMode, noOfColumns));

let newViewState = MoveOperations.moveLeft(context.config, context.viewModel, cursor.viewState, inSelectionMode, noOfColumns);

if (noOfColumns === 1 && newViewState.position.lineNumber !== cursor.viewState.position.lineNumber) {
// moved over to the previous view line
const newViewModelPosition = context.viewModel.coordinatesConverter.convertViewPositionToModelPosition(newViewState.position);
if (newViewModelPosition.lineNumber === cursor.modelState.position.lineNumber) {
// stayed on the same model line => pass wrapping point where 2 view positions map to a single model position
newViewState = MoveOperations.moveLeft(context.config, context.viewModel, newViewState, inSelectionMode, 1);
}
}

result[i] = CursorState.fromViewState(newViewState);
}
return result;
}
Expand All @@ -438,7 +450,18 @@ export class CursorMoveCommands {
let result: CursorState[] = [];
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
result[i] = CursorState.fromViewState(MoveOperations.moveRight(context.config, context.viewModel, cursor.viewState, inSelectionMode, noOfColumns));
let newViewState = MoveOperations.moveRight(context.config, context.viewModel, cursor.viewState, inSelectionMode, noOfColumns);

if (noOfColumns === 1 && newViewState.position.lineNumber !== cursor.viewState.position.lineNumber) {
// moved over to the next view line
const newViewModelPosition = context.viewModel.coordinatesConverter.convertViewPositionToModelPosition(newViewState.position);
if (newViewModelPosition.lineNumber === cursor.modelState.position.lineNumber) {
// stayed on the same model line => pass wrapping point where 2 view positions map to a single model position
newViewState = MoveOperations.moveRight(context.config, context.viewModel, newViewState, inSelectionMode, 1);
}
}

result[i] = CursorState.fromViewState(newViewState);
}
return result;
}
Expand Down
43 changes: 43 additions & 0 deletions src/vs/editor/test/common/controller/cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,49 @@ suite('Editor Controller - Regression tests', () => {
assertCursor(cursor, new Selection(1, 1, 1, 1));
});
});

test('issue #36740: wordwrap creates an extra step / character at the wrapping point', () => {
// a single model line => 4 view lines
withMockCodeEditor([
[
'Lorem ipsum ',
'dolor sit amet ',
'consectetur ',
'adipiscing elit',
].join('')
], { wordWrap: 'wordWrapColumn', wordWrapColumn: 16 }, (editor, cursor) => {
cursor.setSelections('test', [new Selection(1, 7, 1, 7)]);

moveRight(cursor);
assertCursor(cursor, new Selection(1, 8, 1, 8));

moveRight(cursor);
assertCursor(cursor, new Selection(1, 9, 1, 9));

moveRight(cursor);
assertCursor(cursor, new Selection(1, 10, 1, 10));

moveRight(cursor);
assertCursor(cursor, new Selection(1, 11, 1, 11));

moveRight(cursor);
assertCursor(cursor, new Selection(1, 12, 1, 12));

moveRight(cursor);
assertCursor(cursor, new Selection(1, 13, 1, 13));

// moving to view line 2
moveRight(cursor);
assertCursor(cursor, new Selection(1, 14, 1, 14));

moveLeft(cursor);
assertCursor(cursor, new Selection(1, 13, 1, 13));

// moving back to view line 1
moveLeft(cursor);
assertCursor(cursor, new Selection(1, 12, 1, 12));
});
});
});

suite('Editor Controller - Cursor Configuration', () => {
Expand Down

0 comments on commit fa4c556

Please sign in to comment.