# הוסף תמיכה טובה יותר בביטול בעת הכנסת טקסט מעוצב

**URL:** <https://meta.discourse.org/t/add-better-undo-support-when-inserting-formatted-text/214821>\
**Category:** Feature\
**Created:** [14 בינואר,‏ 2022,‏ 4:16am UTC](https://meta.discourse.org/t/add-better-undo-support-when-inserting-formatted-text/214821 "2022-01-14T04:16:44Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [15 בינואר,‏ 2022,‏ 12:27am UTC](https://meta.discourse.org/t/add-better-undo-support-when-inserting-formatted-text/214821/8 "2022-01-15T00:27:55Z")

</div>

We could definitely do better here. A lot of our toolbar buttons and fancy-paste behaviour directly set the value of the textarea in JavaScript. This totally breaks the native browser undo/redo history.

Instead, whenever we make programmatic modifications to the textarea, we should be using `document.execCommand` (as @seanblue mentioned). That way, the browser interprets it the same as a user action, and inserts it cleanly into the undo/redo history.

> **[Document: execCommand() method - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand)**
>
> The execCommand method implements multiple different commands. Some of them provide access to the clipboard, while others are for editing form inputs, contenteditable elements or entire documents (when switched to design mode).

> the `insertText` command, which you can use to programmatically replace text at the cursor while preserving the undo buffer (edit history) in plain `textarea` and `input` elements.

---

_[View the full topic](https://meta.discourse.org/t/add-better-undo-support-when-inserting-formatted-text/214821)._
