Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html] Leading space character is removed when range formatting #58693

Closed
simonschuh opened this issue Sep 14, 2018 · 3 comments
Closed

[html] Leading space character is removed when range formatting #58693

simonschuh opened this issue Sep 14, 2018 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues verified Verification succeeded
Milestone

Comments

@simonschuh
Copy link

Version

Version: 1.27.2 (user setup)
Commit: f46c4c4
Datum: 2018-09-12T16:17:45.060Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architektur: x64

Steps to Reproduce

Example: <a class="btn"></a>

When i paste some text from clipboard with leading space e.g. " btn-link" the space is immediately removed.

Result: <a class="btnbtn-link"></a>
Expected: <a class="btn btn-link"></a>

When I undo, the space is back there.

@vscodebot vscodebot bot added the editor label Sep 14, 2018
@aeschli aeschli added the html HTML support issues label Sep 17, 2018
@aeschli aeschli changed the title Leading space character is removed when pasting [html] Leading space character is removed when range formatting Sep 17, 2018
@aeschli aeschli added the bug Issue identified by VS Code Team member as probable bug label Sep 17, 2018
@aeschli aeschli added this to the Backlog milestone Sep 17, 2018
@alexdima alexdima removed the editor label Sep 20, 2018
@AHKol
Copy link

AHKol commented Oct 1, 2018

I'm new to VSCode development. If this is a good first bug I will pick it up and give it a shot.

@aeschli
Copy link
Contributor

aeschli commented Oct 2, 2018

@AHKol Thanks for asking. It's a good issue as it's easy to set up and run the test cases. And maybe it's also easy to fix using the right approach. The challenge is to be sure that this will not break other formatting cases.

The code is here: https://github.com/Microsoft/vscode-html-languageservice/blob/master/src/services/htmlFormatter.ts
The tests are here:
https://github.com/Microsoft/vscode-html-languageservice/blob/master/src/test/formatter.test.ts

Check out the repo, run npm install, run the tests with npm test, debug in VSCode win the tests debug configuration

The problem is that the html formatterthat we use (jsbeautify) can format a full html documents, but we also need the capability to format a range. Right now we just use format on the content of the range, which of course only works if the substring is something meaningful. Otherwise if the range is in the middle of some attribute that causes issues like above.

Some ideas are:

  • detect that out range is inside a element and don't format then
  • format the full document and try to figure out what has changed in the range. The good thing about formatters is that they only add/remove whitespace. We can find things again with a scanner (which we have, see htmlScanner) as all symbols appear in the same order.

@aeschli
Copy link
Contributor

aeschli commented Oct 29, 2018

@octref octref added the verified Verification succeeded label Nov 1, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants