vscode-stretchy-spaces icon indicating copy to clipboard operation
vscode-stretchy-spaces copied to clipboard

Fix included/excluded languages, temp extra spacing when when typing, and inline diff editor

Open baincd opened this issue 1 year ago • 0 comments

First I would like to say thank you so much for this extension. This is one of my most favorite extensions in any IDE ever!

I have 3 bug fixes in this PR, each completed in their own commit. I'm submitting them together in a single PR for simplicity, but if you would prefer them to be separated out I would be happy to do that.

I've been testing these fixes for the past month with no issues.

1. Fix for included/excluded languages

Issue

  1. Configure the following settings
    "stretchySpaces.includedLanguages": [
        "java"
    ],
    "editor.tabSize": 2
  1. Open a plaintext file with some lines indented with 2 spaces. When first opened, stretchy-spaces is not enabled on the editor as expected (per the configuration)
  2. However, once you start modifying the file, stretchy-spaces is incorrectly enabled

Fix

The root cause is the checkLanguage function checks to see if the languageId has changed, and if it has not then it always returns true. My fix is when the languageId has not changed, to return the same value as the previous check.

2. Fix spaces briefly appear between characters on a new line. (#4)

Fixed by setting the range behavior on each range to ClosedClosed.

3. Fix inline diff editors don't work correctly

Inline diff editor uses stretchy-spaces for unchanged and added lines, however deleted lines do not have spaces stretched.

Example: In this screenshot the indentation has not been changed, however stretchy-spaces makes it appear it has changed: image

Since the extension can't stretch the indentation on the deleted lines in inline mode, I disabled decorations when the editor is a diff editor and in inline mode. I also added an onDidChangeConfiguration listener for when the diff editor is toggled between inline and side-by-side mode.

To determine if the editor is a diff editor, I used some information from https://github.com/microsoft/vscode/issues/15513#issuecomment-1245403215

Sometimes when switching from side-by-side to inline, clear decorations doesn't work. I'm not sure why - I tried multiple things, including executing clearDecorations using setTimeout, and not creating a new currentIndentDecorationType object. To work around this scenario, I open a new file and immediately close it. The editor is refreshed and it works well. This is admittedly a hack-y work around, but I have not noticed any issues.

baincd avatar Apr 28 '24 14:04 baincd