Browse Source

enhance(ux): add undo/redo on mobile

Tienson Qin 1 day ago
parent
commit
d1abefab02
1 changed files with 29 additions and 4 deletions
  1. 29 4
      src/main/mobile/components/editor_toolbar.cljs

+ 29 - 4
src/main/mobile/components/editor_toolbar.cljs

@@ -3,6 +3,7 @@
   (:require [frontend.colors :as colors]
             [frontend.commands :as commands]
             [frontend.handler.editor :as editor-handler]
+            [frontend.handler.history :as history]
             [frontend.mobile.camera :as mobile-camera]
             [frontend.mobile.haptics :as haptics]
             [frontend.mobile.util :as mobile-util]
@@ -67,6 +68,26 @@
               (blur-if-compositing)
               (editor-handler/indent-outdent indent?))})
 
+(defn- undo-action
+  []
+  {:id "undo"
+   :title "Undo"
+   :system-icon "arrow.uturn.backward"
+   :event? true
+   :handler (fn []
+              (blur-if-compositing)
+              (history/undo!))})
+
+(defn- redo-action
+  []
+  {:id "redo"
+   :title "Redo"
+   :system-icon "arrow.uturn.forward"
+   :event? true
+   :handler (fn []
+              (blur-if-compositing)
+              (history/redo!))})
+
 (defn- todo-action
   []
   {:id "todo"
@@ -143,20 +164,24 @@
   (let [audio (audio-action)
         keyboard (keyboard-action)
         main-actions (if quick-add?
-                       [(todo-action)
+                       [(undo-action)
+                        (todo-action)
                         audio
                         (camera-action)
                         (tag-action)
                         (page-ref-action)
                         (indent-outdent-action false)
-                        (indent-outdent-action true)]
-                       [(todo-action)
+                        (indent-outdent-action true)
+                        (redo-action)]
+                       [(undo-action)
+                        (todo-action)
                         (indent-outdent-action false)
                         (indent-outdent-action true)
                         (tag-action)
                         (camera-action)
                         (page-ref-action)
-                        (slash-action)])]
+                        (slash-action)
+                        (redo-action)])]
     {:main main-actions
      :trailing (if quick-add? (capture-action) keyboard)}))