Skip to content

Commit

Permalink
Scroll the window to cursor on move/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sgryjp committed Oct 17, 2018
1 parent fa2e573 commit 40752b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on
to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Now scrolls the window so that the cursor is always visible except when there are multiple cursors

## [1.1.0] - 2018-09-24
### Added
- Multi-cursor support
- New command `extension.deleteWordRight` with keyboard shortcut <kbd>Ctrl+Delete</kbd>
Expand Down
20 changes: 20 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export function cursorNextWordEndJa(
editor.selections = editor.selections
.map(s => positionOfNextWordEnd(document, s.active, wordSeparators))
.map(p => new Selection(p, p));
if (editor.selections.length === 1) {
editor.revealRange(editor.selection);
}
}

export function cursorNextWordEndSelectJa(
Expand All @@ -88,6 +91,9 @@ export function cursorNextWordEndSelectJa(
s.anchor,
positionOfNextWordEnd(editor.document, s.active, wordSeparators))
);
if (editor.selections.length === 1) {
editor.revealRange(editor.selection);
}
}

export function cursorPrevWordStartJa(
Expand All @@ -98,6 +104,9 @@ export function cursorPrevWordStartJa(
editor.selections = editor.selections
.map(s => positionOfPrevWordStart(document, s.active, wordSeparators))
.map(p => new Selection(p, p));
if (editor.selections.length === 1) {
editor.revealRange(editor.selection);
}
}

export function cursorPrevWordStartSelectJa(
Expand All @@ -109,6 +118,9 @@ export function cursorPrevWordStartSelectJa(
s.anchor,
positionOfPrevWordStart(editor.document, s.active, wordSeparators)
));
if (editor.selections.length === 1) {
editor.revealRange(editor.selection);
}
}

export function deleteWordRight(
Expand All @@ -125,6 +137,10 @@ export function deleteWordRight(
for (let selection of selections) {
e.delete(selection);
}
}).then(() => {
if (editor.selections.length === 1) {
editor.revealRange(editor.selection);
}
});
}

Expand All @@ -142,6 +158,10 @@ export function deleteWordLeft(
for (let selection of selections) {
e.delete(selection);
}
}).then(() => {
if (editor.selections.length === 1) {
editor.revealRange(editor.selection);
}
});
}

Expand Down

0 comments on commit 40752b2

Please sign in to comment.