# Fixing Ctrl + Z for editor toolbar button actions in non-Firefox browsers

**URL:** https://meta.discourse.org/t/fixing-ctrl-z-for-editor-toolbar-button-actions-in-non-firefox-browsers/66666
**Category:** Feature
**Created:** [7월 23, 2017, 12:08오후 UTC](https://meta.discourse.org/t/fixing-ctrl-z-for-editor-toolbar-button-actions-in-non-firefox-browsers/66666 "2017-07-23T12:08:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sujan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sujan/32/70979_2.png) [@Sujan](https://meta.discourse.org/u/Sujan)
#### Post date: [7월 23, 2017, 12:08오후 UTC](https://meta.discourse.org/t/fixing-ctrl-z-for-editor-toolbar-button-actions-in-non-firefox-browsers/66666/1 "2017-07-23T12:08:33Z")

</div>

Using the editor toolbar in e.g. Chrome has unintended effects:

If you try to undo the changes done to your text with Ctrl + Z, this will not work. Instead the last change done before using the toolbar button will be undone, leaving the changes from the toolbar buttons in place. Unquoting, unstyling, unpreformat a paragraph can be very cumbersome.

A [previous discussion](https://meta.discourse.org/t/undo-ctrl-cmd-z-doesnt-work-for-markdown/51026) was closed to avoid bikeshedding, but as I ~~don’t agree~~ want to get this fixed I asked for clarification and was told to open a new topic. Here we go:

I think the current, unwanted bahaviour, is caused by the direct setting of `value` in the toolbar actions code: [discourse/app/assets/javascripts/discourse/components/d-editor.js.es6 at 91a91d57f006118c4f306b42f63a276cd6cda5ff · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/91a91d57f006118c4f306b42f63a276cd6cda5ff/app/assets/javascripts/discourse/components/d-editor.js.es6#L502) Only Firefox likes it this way, all other browsers seem to like `document.execCommand('insertText', ...)` better.

Research on this is here:  
[https://stackoverflow.com/questions/7553430/javascript-textarea-undo-redo/10345596#10345596](https://stackoverflow.com/questions/7553430/javascript-textarea-undo-redo/10345596#10345596)  
[https://stackoverflow.com/a/27028331/252627](https://stackoverflow.com/a/27028331/252627)  
[https://codepen.io/netsi1964/pen/QbLLGW](https://codepen.io/netsi1964/pen/QbLLGW)  
[Can I use... Support tables for HTML5, CSS3, etc](http://caniuse.com/#feat=document-execcommand)

Wouldn’t it make sense to implement a `setValue()` and differentiate between browser there?

* * *

Next steps on this would include:

- Map the current state of functionality (state right now: Firefox works, Chrome doesn’t - what about Safari, Opera, etc?)
- Which browser are officially supported by Discourse?
- Are there other files involved in this functionality that I didn’t find?
- Maybe look into how other editors handle this functionality - this has to have been implemented a dozen times already.

---

<div class="post-metadata">

### Author: ![Mohammad\_Asad](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohammad_asad/32/75683_2.png) [@Mohammad\_Asad](https://meta.discourse.org/u/Mohammad_Asad)
#### Post date: [7월 23, 2017, 1:18오후 UTC](https://meta.discourse.org/t/fixing-ctrl-z-for-editor-toolbar-button-actions-in-non-firefox-browsers/66666/2 "2017-07-23T13:18:33Z")

</div>

What roblem are you facing?

---

<div class="post-metadata">

### Author: ![Sujan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sujan/32/70979_2.png) [@Sujan](https://meta.discourse.org/u/Sujan)
#### Post date: [7월 23, 2017, 2:19오후 UTC](https://meta.discourse.org/t/fixing-ctrl-z-for-editor-toolbar-button-actions-in-non-firefox-browsers/66666/3 "2017-07-23T14:19:34Z")

</div>

See the previous discussion I linked to:

> [@Undo (Ctrl/Cmd+Z) doesn't work for Markdown](https://meta.discourse.org/t/undo-ctrl-cmd-z-doesnt-work-for-markdown/51026):
>
> You can’t undo (Ctrl/Cmd+Z) Markdown formatting (e.g., bold). Steps to replicate: Start a new topic. Write three words. Highlight the second word and press Ctrl/Cmd+B Press Ctrl/Cmd+Z Expected result: Asterisks would be removed Actual result: Different in different browsers tested (Safari & Chrome on macOS), but not the expected result.

(Note: It works as expected in Firefox, but not most other browsers)
