Skip to content

Commit

Permalink
don't add fake vspace on vertical movement with word wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jun 8, 2021
1 parent 39790b1 commit 79c4790
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the "vscode-fake-virtual-space" extension will be documented in this file.

## 0.1.1

- Don't add fake vspace on vertical movement with word wrap

## 0.1.0

- First packaged version
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ It also adds the undo/redo commands and binds them to *Ctrl+Z/Y*:

- Multiple cursors don't cause fake virtual space to appear.
- Fake vspace is not cleaned up when the *find/replace* popup causes selection changes. This is difficult to fix because cleaning up is done with the *undo* command and the popup is going to receive this command when in focus. See reason 2 below.
- Clicking on empty space outside existing fake vspace won't create more fake vspace. Could be fixable if there's a mouse click event with readable click row/column.
- Clicking on empty space outside existing fake vspace won't create more fake vspace. See reason 3 below.
- Document is shown as unsaved when fake vspace exists and vspace is not cleaned up on save. This is intended because the best solution seems to be to warn the user about saved fake space. Removing it properly is tricky if undo/redo stack is to be maintained because of reasons 1 and 2 described below.
- Fake vspace state may get lost when saving untitled documents. Could be fixable if could store document metadata that persisted through saves with *untitled:* to *file:* uri changes.
- Move/copy line up/down burns in fake vspace. It's easy to fix by introducing more keybindings but I'm not sure if it's worth it.
- No fake vspace is added when the cursor is moved vertically and word wrap is on.

Some of these issues are difficult to fix because:

1. There's [no undo stack api](https://stackoverflow.com/questions/57900097/where-to-find-vscode-undo-stack-documentation), the stack can only be manipulated by running *undo/redo* commands. Undos are used to alter/clean up fake vspace in order not to clog the stack with these changes.
2. *Undo/redo* commands are going to work as intended only if the document text has focus yet it's impossible to check if it's the case from inside of the command/event handler code. It's possible to check from [keybindings *when clauses*](https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts) though.
3. [No mouse pointer events are provided by the api](https://github.com/Microsoft/vscode/issues/47239). It's only possible to know that the cursor has moved to some (line,character)-position that is always inside the existing text, not (x,y)-position that exist independently of the text.
9 changes: 8 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ async function cursorHorizontalMove(moveCommand:string,moveDelta:number) {
}

async function cursorVerticalMove(moveCommand:string) {
// console.log(
// 'word wrap:',
// vscode.workspace.getConfiguration('editor',vscode.window.activeTextEditor!.document).get('wordWrap')
// )


const releaseLock=await lock.acquire()
try {
const editor=vscode.window.activeTextEditor!
Expand All @@ -183,7 +189,8 @@ async function cursorVerticalMove(moveCommand:string) {
editor.document.lineAt(selectionAfter.active).text
)
await cleanupVspace(editor)
if (insertion!=null) {
const isWordWrapOn=vscode.workspace.getConfiguration('editor',editor.document).get('wordWrap')=='on'
if (insertion!=null && !isWordWrapOn) {
await doVspace(editor,insertion)
}
} finally {
Expand Down

0 comments on commit 79c4790

Please sign in to comment.