Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
x17jiri committed Nov 30, 2024
1 parent 05e9376 commit 99643a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/vs/editor/common/cursor/cursorMoveOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,22 @@ export class MoveOperations {
if (lineNumber < 1) {
lineNumber = 1;
if (allowMoveOnEdgeLine) {
column = model.getLineMinColumn(lineNumber);
const firstColumn = model.getLineMinColumn(lineNumber);
if (column === firstColumn) {
columnHint = null;
}
column = firstColumn;
} else {
column = Math.min(model.getLineMaxColumn(lineNumber), column);
}
} else if (lineNumber > lineCount) {
lineNumber = lineCount;
if (allowMoveOnEdgeLine) {
column = model.getLineMaxColumn(lineNumber);
const lastColumn = model.getLineMaxColumn(lineNumber);
if (column === lastColumn) {
columnHint = null;
}
column = lastColumn;
} else {
column = Math.min(model.getLineMaxColumn(lineNumber), column);
}
Expand Down
5 changes: 4 additions & 1 deletion src/vs/editor/common/virtualSpaceSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export class PositionTripple {
) { }

public static fromModelPosition(model: ICursorSimpleModel, position: Position): PositionTripple {
const maxColumn = model.getLineMaxColumn(position.lineNumber);
// As far as I can tell, during normal editing the line numbers are always valid.
// However some unit tests use values out of range. To be on the safe side, I'm patching it here.
const lineNumberIsValid = position.lineNumber >= 1 && position.lineNumber <= model.getLineCount();
const maxColumn = lineNumberIsValid ? model.getLineMaxColumn(position.lineNumber) : 1;
if (position.column > maxColumn) {
return new PositionTripple(new Position(position.lineNumber, maxColumn), position.column - maxColumn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ suite('Auto Indent On Type - PHP', () => {
]
];
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
editor.setSelection(new Selection(1, 54, 1, 54));
editor.setSelection(new Selection(1, 19, 1, 19));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
"preg_replace('{');",
Expand Down

0 comments on commit 99643a1

Please sign in to comment.