vscode: Redo history is lost when saving HTML file and FormatOnSave results in no changes

Does this issue occur when all extensions are disabled?: Yes

  • Version: 1.67.2
  • Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
  • Date: 2022-05-17T18:20:04.972Z (1 day ago)
  • Electron: 17.4.1
  • Chromium: 98.0.4758.141
  • Node.js: 16.13.0
  • V8: 9.8.177.13-electron.0
  • OS: Darwin arm64 21.4.0

Steps to Reproduce:

  1. Set "files.insertFinalNewline": true
  2. Create and save a HTML file with some content => a newline is ensured at the end of the file, this is good
  3. Make a change and save
  4. Undo once => nothing happens, this is bad
  5. Undo a second time => the changes are undone
  6. Save the undone changes
  7. Try to redo => nothing happens, there’s no redo history

Then change the language mode from HTML to Plain Text and repeat the steps: step 5 is not needed because only one undo is needed, which is correct, and step 7 succeeds because the redo history is kept after saving.

I’m used to being able to undo, save, and then redo, when any automatic formatting that occurs results in no changes (i.e. the file is properly formatted in all stages of the undo/redo history). I’ve been doing this consistently for the past 2-3 years, even with editorconfig and rubocop. I rely a lot on my redo history.

Seems like the bug is that an extra stage is added into the undo history when files.insertFinalNewline applies to the file, even though it results in no differences. Also occurs when files.insertFinalNewline is turned off and I have editorconfig insert_final_newline = true and extensions enabled; the reproduction steps above where written with extensions disabled, but the effect is the same: an extra stage added to the undo/redo history that contains no changes, so shouldn’t be there.

Cheers, H =)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

I can reproduce when both these settings are enabled:

  • "files.insertFinalNewline": true
  • "editor.formatOnSave": true

Steps:

  • empty window, fresh user data dir
  • apply those settings
  • new index.html file
  • first line type something and save
  • type something again at the end of line and save
  • undo

=> 🐛 nothing happens

This seems to require both format on save and adding final new line.