# Bug with highlightTrailingWhitespace() and entering a new line and pressing command + z

**URL:** <https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213>\
**Category:** v6\
**Created:** [May 10, 2025, 3:10pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213 "2025-05-10T15:10:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paladox](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/paladox/32/3274_2.png) [@paladox](https://discuss.codemirror.net/u/paladox)\
**Post date:** [May 10, 2025, 3:10pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/1 "2025-05-10T15:10:53Z")

</div>

Hi, my CM extension setup is [plugins\_codemirror-editor/web/element/extensions.ts at master · GerritCodeReview/plugins\_codemirror-editor · GitHub](https://github.com/GerritCodeReview/plugins_codemirror-editor/blob/master/web/element/extensions.ts). The issue I’m having is that when I get a piece of code to go onto a new line, it shows the previous line with whitespace (correct behaviour). Now when I press command + z to revert back to the previous text, it correctly does it but the whitespace stuff is still shown. It’s a bug since reloading the page gets rids of it.

You can see a video here [https://imgur.com/a/OlLi6RW](https://imgur.com/a/OlLi6RW)

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 10, 2025, 3:25pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/2 "2025-05-10T15:25:35Z")

</div>

If you can reduce this to a couple of lines of code on [codemirror.net/try](https://codemirror.net/try), I can take a look. If it only occurs with all that custom code loaded, the problem might not be in the library.

---

<div class="post-metadata">

**Author:** ![paladox](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/paladox/32/3274_2.png) [@paladox](https://discuss.codemirror.net/u/paladox)\
**Post date:** [May 10, 2025, 3:38pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/3 "2025-05-10T15:38:56Z")

</div>

Yup I can reproduce on /try as well.

```import
import {javascript} from "@codemirror/lang-javascript"
import {
  EditorView,
  keymap,
  highlightSpecialChars,
  drawSelection,
  lineNumbers,
  highlightActiveLineGutter,
  highlightWhitespace,
  highlightTrailingWhitespace,
} from '@codemirror/view';

new EditorView({
  doc: "console.log('hello')\n",
  extensions: [basicSetup, javascript(), highlightTrailingWhitespace()],
  parent: document.body
})

```

video: [https://imgur.com/a/Nj8U5ju](https://imgur.com/a/Nj8U5ju)

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 10, 2025, 4:24pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/4 "2025-05-10T16:24:14Z")

</div>

Thanks, I could reproduce this. This patch should help.

> <https://github.com/codemirror/view/commit/4e130aad410b02afb328f3089557d7cc1b17a524>
>
> FIX: Fix an issue in \`MatchDecorator\` causing \`updateDeco\` to sometimes not
> do t…he right thing for deletions.
> 
> See https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213

---

<div class="post-metadata">

**Author:** ![paladox](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/paladox/32/3274_2.png) [@paladox](https://discuss.codemirror.net/u/paladox)\
**Post date:** [May 10, 2025, 4:44pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/5 "2025-05-10T16:44:58Z")

</div>

Thank you!!

---

<div class="post-metadata">

**Author:** ![paladox](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/paladox/32/3274_2.png) [@paladox](https://discuss.codemirror.net/u/paladox)\
**Post date:** [May 10, 2025, 7:25pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/6 "2025-05-10T19:25:01Z")

</div>

Is there any chance of a minor release please? 🙂

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 12, 2025, 2:10pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/7 "2025-05-12T14:10:28Z")

</div>

Yes—I’ve tagged 6.36.8

---

<div class="post-metadata">

**Author:** ![paladox](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/paladox/32/3274_2.png) [@paladox](https://discuss.codemirror.net/u/paladox)\
**Post date:** [May 13, 2025, 6:35pm UTC](https://discuss.codemirror.net/t/bug-with-highlighttrailingwhitespace-and-entering-a-new-line-and-pressing-command-z/9213/8 "2025-05-13T18:35:48Z")

</div>

Thank you so much!
