From 79c479069b67e63b3920dfd5d1ca5a0785ee62e2 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 9 Jun 2021 00:54:24 +0300 Subject: [PATCH] don't add fake vspace on vertical movement with word wrap --- CHANGELOG.md | 4 ++++ README.md | 4 +++- src/extension.ts | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66af735..91c1b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 0f8a222..de7e46a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/extension.ts b/src/extension.ts index 700fe75..60e6d7d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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! @@ -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 {