history.mdx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ---
  2. title: History Module
  3. ---
  4. The History module is responsible for handling undo and redo for Quill. It can be configured with the following options:
  5. ## Configuration
  6. #### delay
  7. - Default: `1000`
  8. Changes occuring within the `delay` number of milliseconds are merged into a single change.
  9. For example, with delay set to `0`, nearly every character is recorded as one change and so undo would undo one character at a time. With delay set to `1000`, undo would undo all changes that occured within the last 1000 milliseconds.
  10. #### maxStack
  11. - Default: `100`
  12. Maximum size of the history's undo/redo stack. Merged changes with the `delay` option counts as a singular change.
  13. #### userOnly
  14. - Default: `false`
  15. By default all changes, whether originating from user input or programmatically through the API, are treated the same and change be undone or redone by the history module. If `userOnly` is set to `true`, only user changes will be undone or redone.
  16. ### Example
  17. ```javascript
  18. const quill = new Quill('#editor', {
  19. modules: {
  20. history: {
  21. delay: 2000,
  22. maxStack: 500,
  23. userOnly: true
  24. },
  25. },
  26. theme: 'snow'
  27. });
  28. ```
  29. ## API
  30. #### clear
  31. Clears the history stack.
  32. **Methods**
  33. ```js
  34. clear()
  35. ```
  36. **Examples**
  37. ```js
  38. quill.history.clear();
  39. ```
  40. #### cutoff
  41. Normally changes made in short succession (configured by `delay`) are merged as a single change, so that triggering an undo will undo multiple changes. Using `cutoff()` will reset the merger window so that a changes before and after `cutoff()` is called will not be merged.
  42. **Methods**
  43. ```js
  44. cutoff()
  45. ```
  46. **Examples**
  47. ```js
  48. quill.history.cutoff();
  49. ```
  50. #### undo
  51. Undo last change.
  52. **Methods**
  53. ```js
  54. undo()
  55. ```
  56. **Examples**
  57. ```js
  58. quill.history.undo();
  59. ```
  60. #### redo
  61. If last change was an undo, redo this undo. Otherwise does nothing.
  62. **Methods**
  63. ```js
  64. redo()
  65. ```
  66. **Examples**
  67. ```js
  68. quill.history.redo();
  69. ```