Skip to content

Commit 7413730

Browse files
committed
Get rid of Position.getLineEndIncludingEOL
The TODO was right, as far as I can tell
1 parent 4cc7767 commit 7413730

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

src/actions/plugins/replaceWithRegister.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ReplaceOperator extends BaseOperator {
2525
public async run(vimState: VimState, start: Position, end: Position): Promise<void> {
2626
const range =
2727
vimState.currentRegisterMode === RegisterMode.LineWise
28-
? new Range(start.getLineBegin(), end.getLineEndIncludingEOL())
28+
? new Range(start.getLineBegin(), end.getLineEnd())
2929
: new Range(start, end.getRight());
3030

3131
const register = await Register.get(vimState.recordedState.registerName, this.multicursorIndex);

src/cmd_line/commands/delete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class DeleteCommand extends ExCommand {
5252
*/
5353
private deleteRange(startLine: number, endLine: number, vimState: VimState): void {
5454
let start = new Position(startLine, 0);
55-
let end = new Position(endLine, 0).getLineEndIncludingEOL();
55+
let end = new Position(endLine, 0).getLineEnd();
5656

5757
if (endLine < vimState.document.lineCount - 1) {
5858
end = end.getRightThroughLineBreaks();
@@ -69,7 +69,7 @@ export class DeleteCommand extends ExCommand {
6969

7070
vimState.recordedState.transformer.addTransformation({
7171
type: 'deleteRange',
72-
range: new vscode.Range(start, end),
72+
range,
7373
manuallySetCursorPositions: true,
7474
});
7575
vimState.cursorStopPosition = start.getLineBegin();

src/cmd_line/commands/move.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class MoveCommand extends ExCommand {
6969
}
7070
// delete
7171
let start = new Position(sourceStart, 0);
72-
let end = new Position(sourceEnd, 0).getLineEndIncludingEOL();
72+
let end = new Position(sourceEnd, 0).getLineEnd();
7373

7474
if (sourceEnd < vimState.document.lineCount - 1) {
7575
end = end.getRightThroughLineBreaks();

src/common/motion/position.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ declare module 'vscode' {
211211
*/
212212
getLineEnd(): Position;
213213

214-
/**
215-
* @returns a new Position at the end of this Position's line, including the invisible newline character.
216-
*/
217-
getLineEndIncludingEOL(): Position;
218-
219214
/**
220215
* @returns a new Position one to the left if this Position is on the EOL. Otherwise, returns this position.
221216
*/
@@ -482,14 +477,6 @@ Position.prototype.getLineEnd = function (this: Position): Position {
482477
return new Position(this.line, TextEditor.getLineLength(this.line));
483478
};
484479

485-
/**
486-
* @returns a new Position at the end of this Position's line, including the invisible newline character.
487-
*/
488-
Position.prototype.getLineEndIncludingEOL = function (this: Position): Position {
489-
// TODO: isn't this one too far?
490-
return new Position(this.line, TextEditor.getLineLength(this.line) + 1);
491-
};
492-
493480
/**
494481
* @returns a new Position one to the left if this Position is on the EOL. Otherwise, returns this position.
495482
*/

src/mode/modeHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
15581558
for (const { stop: cursorStop } of this.vimState.cursors) {
15591559
if (cursorStop.isLineEnd(this.vimState.document)) {
15601560
iModeVirtualCharDecorationOptions.push({
1561-
range: new vscode.Range(cursorStop, cursorStop.getLineEndIncludingEOL()),
1561+
range: new vscode.Range(cursorStop, cursorStop.getLineEnd()),
15621562
renderOptions: eolRenderOptions,
15631563
});
15641564
} else {

test/cmd_line/delete.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { newTest } from '../testSimplifier';
2+
3+
suite(':d[elete]', () => {
4+
newTest({
5+
title: ':d',
6+
start: ['line 1', 'li|ne 2', 'line 3'],
7+
keysPressed: ':d' + '\n',
8+
end: ['line 1', '|line 3'],
9+
});
10+
11+
newTest({
12+
title: ':2,3d',
13+
start: ['line 1', 'li|ne 2', 'line 3'],
14+
keysPressed: ':2,3d' + '\n',
15+
end: ['|line 1'],
16+
});
17+
18+
newTest({
19+
title: ':d 2',
20+
start: ['line 1', 'li|ne 2', 'line 3'],
21+
keysPressed: ':d 2' + '\n',
22+
end: ['|line 1'],
23+
});
24+
});

0 commit comments

Comments
 (0)