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] Pasting HTML code adds extra closing tag on first line #227859

Closed
nickbstudy opened this issue Sep 7, 2024 · 7 comments
Closed

[html] Pasting HTML code adds extra closing tag on first line #227859

nickbstudy opened this issue Sep 7, 2024 · 7 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues

Comments

@nickbstudy
Copy link

Type: Bug

Paste something like

hello world

and it will automatically insert a closing tag for the first line, showing up as:

hello world

VS Code version: Code 1.93.0 (4849ca9, 2024-09-04T13:02:38.431Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-13700F (24 x 2112)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 63.83GB (50.92GB free)
Process Argv --crash-reporter-id f57729e2-1416-48b3-8c6b-c2a08645c162
Screen Reader no
VM 0%
Extensions (17)
Extension Author (truncated) Version
ng-template Ang 18.2.0
emmet-jss car 1.0.0
es7-react-js-snippets dsz 4.4.3
auto-rename-tag for 0.1.10
vscode-docker ms- 1.29.2
csdevkit ms- 1.10.16
csharp ms- 2.45.20
vscode-dotnet-runtime ms- 2.1.5
vscodeintellicode-csharp ms- 2.1.11
debugpy ms- 2024.10.0
python ms- 2024.14.0
vscode-pylance ms- 2024.8.2
remote-containers ms- 0.384.0
remote-wsl ms- 0.88.2
LiveServer rit 5.7.9
markdown-preview-enhanced shd 0.8.13
JavaScriptSnippets xab 1.8.0
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
01bff139:31013167
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
newcmakeconfigv2:31071590
impr_priority:31102340
nativerepl1:31104043
refactort:31108082
pythonrstrctxt:31112756
flightc:31119335
wkspc-onlycs-t:31132770
wkspc-ranged-t:31125599
ei213698:31121563

@AlexDawsonUK
Copy link

Can confirm, reproducable with the following steps.

  1. Paste the following into an HTML5 formatted document
<select>
	<option value="1">Americano</option>
	<option value="2">Latte</option>
	<option value="3">Green Tea</option>
</select>

VSCode adds a closing tag seen here...

<select></select>
	<option value="1">Americano</option>
	<option value="2">Latte</option>
	<option value="3">Green Tea</option>
</select>

Currently can only be resolved with Settings > HTML: Auto Closing Tags (Disable).

Version: 1.93.0 (Universal)
Commit: 4849ca9
Date: 2024-09-04T13:02:38.431Z
Electron: 30.4.0
ElectronBuildId: 10073054
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Darwin arm64 23.6.0

@aeschli aeschli changed the title Pasting HTML code adds extra closing tag on first line [html] Pasting HTML code adds extra closing tag on first line Sep 10, 2024
@aeschli aeschli added bug Issue identified by VS Code Team member as probable bug html HTML support issues labels Sep 10, 2024
@aeschli aeschli added this to the Backlog milestone Sep 10, 2024
@aeschli aeschli modified the milestones: Backlog, September 2024 Sep 12, 2024
@aeschli
Copy link
Contributor

aeschli commented Sep 12, 2024

There was a change in how the paste is reported on the extension side.
Instead of a single TextDocumentChangeEvent, we now get one event per line.

@hediet Any idea if that change was intended?

@aeschli aeschli added the candidate Issue identified as probable candidate for fixing in the next release label Sep 12, 2024
@aeschli
Copy link
Contributor

aeschli commented Sep 12, 2024

Sorry, I was wrong, nothing has changed with the TextDocumentChangeEvent.

The bug is caused by

const position = new Position(rangeStart.line, rangeStart.character + lastChange.text.length);
(thans @hediet for finding this out).
There can be eol-characters in lastChange.text. The new Position is then not valid with a character offset far off.

We only see this now as the last HTML service update (ce9ce04) included an update of the TextDocument, where we now handle invalid positions and normalize them as spec'ed.: microsoft/vscode-languageserver-node#1286

The workaround for users is to manually remove the inserted code, or, if that's too much of a hassle, turn off the auto close feature: "html.autoClosingTags": false

@LucasOe
Copy link

LucasOe commented Oct 3, 2024

Has this been fixed in version 1.94 with #228662? This issue is still open.

@dailytabs
Copy link

Had the issue, which led me here. Noticed the update icon after seeing the last comment. Help: About is now showing 1.94.0. Still had the code on my clipboard, pasted it again, and no ending tag was added.

@siakaramalegos
Copy link

Thanks, @dailytabs for mentioning that. I can confirm that after updating to 1.94.2, the bug seems to be fixed for me too. I'm so happy because this was so annoying. I kept wondering why my code changes were so weird and forgetting the extra closing tag it kept inserting. Thanks, all!

@aeschli aeschli added this to the September 2024 milestone Oct 24, 2024
@aeschli aeschli closed this as completed Oct 24, 2024
@nickbstudy
Copy link
Author

nickbstudy commented Oct 25, 2024 via email

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 8, 2024
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
Projects
None yet
Development

No branches or pull requests

8 participants