Skip to content

Commit

Permalink
Added remembering end key state behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanrhu committed Jan 15, 2020
1 parent 73bcc76 commit 558664f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"applicationinsights": "1.0.8",
"chokidar": "3.2.3",
"graceful-fs": "4.1.11",
"gulp-bom": "^3.0.0",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.3",
"iconv-lite": "0.5.0",
Expand Down
11 changes: 8 additions & 3 deletions src/vs/editor/common/controller/cursorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,21 @@ export class SingleCursorState {
public readonly position: Position;
public readonly leftoverVisibleColumns: number;
public readonly selection: Selection;
public readonly isEnd: boolean;

constructor(
selectionStart: Range,
selectionStartLeftoverVisibleColumns: number,
position: Position,
leftoverVisibleColumns: number,
isEnd: boolean = false
) {
this.selectionStart = selectionStart;
this.selectionStartLeftoverVisibleColumns = selectionStartLeftoverVisibleColumns;
this.position = position;
this.leftoverVisibleColumns = leftoverVisibleColumns;
this.selection = SingleCursorState._computeSelection(this.selectionStart, this.position);
this.isEnd = isEnd;
}

public equals(other: SingleCursorState) {
Expand All @@ -304,22 +307,24 @@ export class SingleCursorState {
return (!this.selection.isEmpty() || !this.selectionStart.isEmpty());
}

public move(inSelectionMode: boolean, lineNumber: number, column: number, leftoverVisibleColumns: number): SingleCursorState {
public move(inSelectionMode: boolean, lineNumber: number, column: number, leftoverVisibleColumns: number, isEnd: boolean = false): SingleCursorState {
if (inSelectionMode) {
// move just position
return new SingleCursorState(
this.selectionStart,
this.selectionStartLeftoverVisibleColumns,
new Position(lineNumber, column),
leftoverVisibleColumns
leftoverVisibleColumns,
isEnd
);
} else {
// move everything
return new SingleCursorState(
new Range(lineNumber, column, lineNumber, column),
leftoverVisibleColumns,
new Position(lineNumber, column),
leftoverVisibleColumns
leftoverVisibleColumns,
isEnd
);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/vs/editor/common/controller/cursorMoveOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ export class MoveOperations {
column = cursor.position.column;
}

if (cursor.isEnd) {
column = model.getLineMaxColumn(lineNumber + 1);
}

let r = MoveOperations.down(config, model, lineNumber, column, cursor.leftoverVisibleColumns, linesCount, true);

return cursor.move(inSelectionMode, r.lineNumber, r.column, r.leftoverVisibleColumns);
return cursor.move(inSelectionMode, r.lineNumber, cursor.isEnd ? column : r.column, r.leftoverVisibleColumns, cursor.isEnd);
}

public static translateDown(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): SingleCursorState {
Expand Down Expand Up @@ -174,9 +178,13 @@ export class MoveOperations {
column = cursor.position.column;
}

if (cursor.isEnd) {
column = model.getLineMaxColumn(lineNumber - 1);
}

let r = MoveOperations.up(config, model, lineNumber, column, cursor.leftoverVisibleColumns, linesCount, true);

return cursor.move(inSelectionMode, r.lineNumber, r.column, r.leftoverVisibleColumns);
return cursor.move(inSelectionMode, r.lineNumber, cursor.isEnd ? column : r.column, r.leftoverVisibleColumns, cursor.isEnd);
}

public static translateUp(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): SingleCursorState {
Expand Down Expand Up @@ -214,7 +222,7 @@ export class MoveOperations {
public static moveToEndOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {
let lineNumber = cursor.position.lineNumber;
let maxColumn = model.getLineMaxColumn(lineNumber);
return cursor.move(inSelectionMode, lineNumber, maxColumn, 0);
return cursor.move(inSelectionMode, lineNumber, maxColumn, 0, true);
}

public static moveToBeginningOfBuffer(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/common/controller/oneCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class OneCursor {
);
const leftoverVisibleColumns = modelState.position.equals(position) ? modelState.leftoverVisibleColumns : 0;

modelState = new SingleCursorState(selectionStart, selectionStartLeftoverVisibleColumns, position, leftoverVisibleColumns);
modelState = new SingleCursorState(selectionStart, selectionStartLeftoverVisibleColumns, position, leftoverVisibleColumns, modelState.isEnd);
}

if (!viewState) {
Expand All @@ -108,12 +108,12 @@ export class OneCursor {
const viewSelectionStart2 = context.convertModelPositionToViewPosition(new Position(modelState.selectionStart.endLineNumber, modelState.selectionStart.endColumn));
const viewSelectionStart = new Range(viewSelectionStart1.lineNumber, viewSelectionStart1.column, viewSelectionStart2.lineNumber, viewSelectionStart2.column);
const viewPosition = context.convertModelPositionToViewPosition(modelState.position);
viewState = new SingleCursorState(viewSelectionStart, modelState.selectionStartLeftoverVisibleColumns, viewPosition, modelState.leftoverVisibleColumns);
viewState = new SingleCursorState(viewSelectionStart, modelState.selectionStartLeftoverVisibleColumns, viewPosition, modelState.leftoverVisibleColumns, modelState.isEnd);
} else {
// Validate new view state
const viewSelectionStart = context.validateViewRange(viewState.selectionStart, modelState.selectionStart);
const viewPosition = context.validateViewPosition(viewState.position, modelState.position);
viewState = new SingleCursorState(viewSelectionStart, modelState.selectionStartLeftoverVisibleColumns, viewPosition, modelState.leftoverVisibleColumns);
viewState = new SingleCursorState(viewSelectionStart, modelState.selectionStartLeftoverVisibleColumns, viewPosition, modelState.leftoverVisibleColumns, viewState.isEnd);
}

this.modelState = modelState;
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3996,6 +3996,14 @@ gulp-azure-storage@^0.10.0:
vinyl "^2.2.0"
vinyl-fs "^3.0.3"

gulp-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/gulp-bom/-/gulp-bom-3.0.0.tgz#b2f1ab0ef304ff5e593665b776ba517ef7ffb4ad"
integrity sha512-iw/J94F+MVlxG64Q17BSkHsyjpY17qHl3N3A/jDdrL77zQBkhKtTiKLqM4di9CUX/qFToyyeDsOWwH+rESBgmA==
dependencies:
plugin-error "^1.0.1"
through2 "^3.0.1"

gulp-buffer@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/gulp-buffer/-/gulp-buffer-0.0.2.tgz#af81b4346101736b49942ec6c9fa867ffe737036"
Expand Down Expand Up @@ -8924,6 +8932,13 @@ through2@^3.0.0:
readable-stream "2 || 3"
xtend "~4.0.1"

through2@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a"
integrity sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==
dependencies:
readable-stream "2 || 3"

through2@~0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/through2/-/through2-0.2.3.tgz#eb3284da4ea311b6cc8ace3653748a52abf25a3f"
Expand Down

0 comments on commit 558664f

Please sign in to comment.