mrmlnc / vscode-csscomb

:electric_plug: VS Code plugin for CSScomb — CSS coding style formatter.
https://goo.gl/lKARa5
MIT License
65 stars 11 forks source link

formatonsave moves cursor at end of file and unfolds every section #112

Closed t-fritsch closed 5 years ago

t-fritsch commented 6 years ago

Environment

Actual behavior

When formatonsave is activated, saving the file places the cursor at the very end of the file, forcing the user to manually move the cursor back to its initial position. The folded sections also gets unfolded, which makes it even more difficult to go back to initial position when working on large css files

Expected behavior

when formatonsave is activated, saving the file should not change the cursor position, it should remain on the line that it was on.

Steps to reproduce

  1. configure vscode csscomb to formatonsave
  2. create a css file and type css code into it
  3. save file issue-vscode-csscomb

Config

"csscomb.formatOnSave": true,

Note: this issue is there because a previous issue was closed by the reporter but never worked on : https://github.com/mrmlnc/vscode-csscomb/issues/110

Edit : this issue doesn't occur when formatOnSave is false and you run command "CSSComb: Format styles" from command palette (CTRL+SHIFT+p).

muuvmuuv commented 6 years ago

@mrmlnc really need a fix for this... it is annoying. Do you have any clue what is doing this? If you have no time and know where to start, I will try my best to make a PR to fix this.

muuvmuuv commented 6 years ago

This might help: https://github.com/Microsoft/vscode/issues/111

nealoke commented 6 years ago

@tfritsch-km any way I can help solve this?

t-fritsch commented 6 years ago

Sorry @nealoke, I really don't know. Maybe ask @mrmlnc where to start (I haven't digged into the code of this plugin yet)

nealoke commented 6 years ago

Aah oops, I thought you were the author, @mrmlnc how can I help with this plugin? :)

t-fritsch commented 6 years ago

no problem 😄

t-fritsch commented 6 years ago

I tried to look at it, and noticed that the code that formats css is slightly different when saving file from the one that runs when formatting with the "CSSComb: Format styles" command :

on "CSSComb: Format styles" command : https://github.com/mrmlnc/vscode-csscomb/blob/65c71c40c8a5dedac9b408e7fa158e8b864ea057/src/extension.ts#L69

on save : https://github.com/mrmlnc/vscode-csscomb/blob/65c71c40c8a5dedac9b408e7fa158e8b864ea057/src/extension.ts#L118

I don't know the difference between the two, anyone that knows vscode api sees something interesting ?

mrmlnc commented 6 years ago

Hey,

Unfortunately, now I don't have free time to support this plugin. When I developed this plugin it was not possible to save the cursor position when we use event.waitUntil(actions). If you want to correct the current behavior, please send a pull request.

t-fritsch commented 6 years ago

Thank you @mrmlnc I just did a PR, could you review it ? I haven't heavily tested it but it seems to work. Any advice on it ?

t-fritsch commented 6 years ago

Hey, I've used the patch for about a week now, and it works fine so far, I didn't notice any regression. Would love to get some feedback.

nealoke commented 5 years ago

@mrmlnc could you please merge this?

markconroy commented 5 years ago

Hi,

I have tested the patch https://github.com/kumquats/vscode-csscomb/commit/8b16d5357dee6880a6b4aa7efd2bda0b263512e9 and csscomb format on save is now working as expected.

It would be great to get this merged to the repo.

nealoke commented 5 years ago

🙏 merge please 😄

aldenfbrown commented 5 years ago

+1 🙏 merge please 😄

t-fritsch commented 5 years ago

Hello, As @mrmlnc said in the PR comments (see https://github.com/mrmlnc/vscode-csscomb/pull/116#issuecomment-422672084) , there is a regression in my code when using the File: Save all command : only the focused editor gets formatted. This PR could however be merged if it gets a config option to enable it (current behavior by default), but I unfortunately have no time to work on it ATM. 😕

t-fritsch commented 5 years ago

So, I just pushed a new commit to PR that should make it work event with File > save all, I hope it produces no regressions this time 😃

zincplusplus commented 5 years ago

@mrmlnc what's holding up this merge?

mrmlnc commented 5 years ago

Fixed by https://github.com/mrmlnc/vscode-csscomb/releases/tag/5.2.3. @tfritsch-km, thanks a lot.