|
|
@@ -50,7 +50,7 @@
|
|
|
(and
|
|
|
(not (fn? command-steps))
|
|
|
(not (contains? (set (map first command-steps)) :editor/input))
|
|
|
- (not (contains? #{"Date Picker" "Template" "Deadline" "Scheduled"} chosen))))]
|
|
|
+ (not (contains? #{"Date Picker" "Template" "Deadline" "Scheduled" "Upload an image"} chosen))))]
|
|
|
(editor-handler/insert-command! id command-steps
|
|
|
format
|
|
|
{:restore? restore-slash?})))
|
|
|
@@ -268,8 +268,7 @@
|
|
|
{:keys [pos]} @*slash-caret-pos
|
|
|
command (:command (first input-option))]
|
|
|
(on-submit command @input-value pos))
|
|
|
- (reset! input-value nil))))}
|
|
|
- nil)))
|
|
|
+ (reset! input-value nil))))})))
|
|
|
{:did-update
|
|
|
(fn [state]
|
|
|
(when-let [show-input (state/get-editor-show-input)]
|
|
|
@@ -360,8 +359,6 @@
|
|
|
input-id id
|
|
|
input (gdom/getElement input-id)
|
|
|
repo (:block/repo block)]
|
|
|
- ;; (.addEventListener input "paste" (fn [event]
|
|
|
- ;; (editor-handler/append-paste-doc! format event)))
|
|
|
(mixins/on-key-down
|
|
|
state
|
|
|
{;; enter
|
|
|
@@ -415,160 +412,158 @@
|
|
|
(not (editor-handler/in-auto-complete? input)))
|
|
|
(editor-handler/on-up-down state e false)))
|
|
|
;; backspace
|
|
|
- 8 (fn [state e]
|
|
|
- (let [node (gdom/getElement input-id)
|
|
|
- current-pos (:pos (util/get-caret-pos node))
|
|
|
- value (gobj/get node "value")
|
|
|
- deleted (and (> current-pos 0)
|
|
|
- (util/nth-safe value (dec current-pos)))
|
|
|
- selected-start (gobj/get node "selectionStart")
|
|
|
- selected-end (gobj/get node "selectionEnd")
|
|
|
- block-id (:block-id (first (:rum/args state)))
|
|
|
- page (state/get-current-page)]
|
|
|
- (cond
|
|
|
- (not= selected-start selected-end)
|
|
|
- nil
|
|
|
-
|
|
|
- (and (zero? current-pos)
|
|
|
- ;; not the top block in a block page
|
|
|
- (not (and page
|
|
|
- (util/uuid-string? page)
|
|
|
- (= (medley/uuid page) block-id))))
|
|
|
-
|
|
|
- (editor-handler/delete-block! state repo e)
|
|
|
-
|
|
|
- (and (> current-pos 1)
|
|
|
- (= (util/nth-safe value (dec current-pos)) commands/slash))
|
|
|
- (do
|
|
|
- (reset! *slash-caret-pos nil)
|
|
|
- (reset! *show-commands false))
|
|
|
-
|
|
|
- (and (> current-pos 1)
|
|
|
- (= (util/nth-safe value (dec current-pos)) commands/angle-bracket))
|
|
|
- (do
|
|
|
- (reset! *angle-bracket-caret-pos nil)
|
|
|
- (reset! *show-block-commands false))
|
|
|
-
|
|
|
- ;; pair
|
|
|
- (and
|
|
|
- deleted
|
|
|
- (contains?
|
|
|
- (set (keys editor-handler/delete-map))
|
|
|
- deleted)
|
|
|
- (>= (count value) (inc current-pos))
|
|
|
- (= (util/nth-safe value current-pos)
|
|
|
- (get editor-handler/delete-map deleted)))
|
|
|
-
|
|
|
- (do
|
|
|
- (util/stop e)
|
|
|
- (commands/delete-pair! id)
|
|
|
- (cond
|
|
|
- (and (= deleted "[") (state/get-editor-show-page-search?))
|
|
|
- (state/set-editor-show-page-search! false)
|
|
|
-
|
|
|
- (and (= deleted "(") (state/get-editor-show-block-search?))
|
|
|
- (state/set-editor-show-block-search! false)
|
|
|
-
|
|
|
- :else
|
|
|
- nil))
|
|
|
-
|
|
|
- ;; deleting hashtag
|
|
|
- (and (= deleted "#") (state/get-editor-show-page-search-hashtag?))
|
|
|
- (state/set-editor-show-page-search-hashtag! false)
|
|
|
-
|
|
|
- :else
|
|
|
- nil)))
|
|
|
+ 8 (fn [state e]
|
|
|
+ (let [node (gdom/getElement input-id)
|
|
|
+ current-pos (:pos (util/get-caret-pos node))
|
|
|
+ value (gobj/get node "value")
|
|
|
+ deleted (and (> current-pos 0)
|
|
|
+ (util/nth-safe value (dec current-pos)))
|
|
|
+ selected-start (gobj/get node "selectionStart")
|
|
|
+ selected-end (gobj/get node "selectionEnd")
|
|
|
+ block-id (:block-id (first (:rum/args state)))
|
|
|
+ page (state/get-current-page)]
|
|
|
+ (cond
|
|
|
+ (not= selected-start selected-end)
|
|
|
+ nil
|
|
|
+
|
|
|
+ (and (zero? current-pos)
|
|
|
+ ;; not the top block in a block page
|
|
|
+ (not (and page
|
|
|
+ (util/uuid-string? page)
|
|
|
+ (= (medley/uuid page) block-id))))
|
|
|
+ (editor-handler/delete-block! state repo e)
|
|
|
+
|
|
|
+ (and (> current-pos 1)
|
|
|
+ (= (util/nth-safe value (dec current-pos)) commands/slash))
|
|
|
+ (do
|
|
|
+ (reset! *slash-caret-pos nil)
|
|
|
+ (reset! *show-commands false))
|
|
|
+
|
|
|
+ (and (> current-pos 1)
|
|
|
+ (= (util/nth-safe value (dec current-pos)) commands/angle-bracket))
|
|
|
+ (do
|
|
|
+ (reset! *angle-bracket-caret-pos nil)
|
|
|
+ (reset! *show-block-commands false))
|
|
|
+
|
|
|
+ ;; pair
|
|
|
+ (and
|
|
|
+ deleted
|
|
|
+ (contains?
|
|
|
+ (set (keys editor-handler/delete-map))
|
|
|
+ deleted)
|
|
|
+ (>= (count value) (inc current-pos))
|
|
|
+ (= (util/nth-safe value current-pos)
|
|
|
+ (get editor-handler/delete-map deleted)))
|
|
|
+
|
|
|
+ (do
|
|
|
+ (util/stop e)
|
|
|
+ (commands/delete-pair! id)
|
|
|
+ (cond
|
|
|
+ (and (= deleted "[") (state/get-editor-show-page-search?))
|
|
|
+ (state/set-editor-show-page-search! false)
|
|
|
+
|
|
|
+ (and (= deleted "(") (state/get-editor-show-block-search?))
|
|
|
+ (state/set-editor-show-block-search! false)
|
|
|
+
|
|
|
+ :else
|
|
|
+ nil))
|
|
|
+
|
|
|
+ ;; deleting hashtag
|
|
|
+ (and (= deleted "#") (state/get-editor-show-page-search-hashtag?))
|
|
|
+ (state/set-editor-show-page-search-hashtag! false)
|
|
|
+
|
|
|
+ :else
|
|
|
+ nil)))
|
|
|
;; tab
|
|
|
- 9 (fn [state e]
|
|
|
- (let [input-id (state/get-edit-input-id)
|
|
|
- input (and input-id (gdom/getElement id))
|
|
|
- pos (and input (:pos (util/get-caret-pos input)))]
|
|
|
- (when-not (state/get-editor-show-input)
|
|
|
- (util/stop e)
|
|
|
- (let [direction (if (gobj/get e "shiftKey") ; shift+tab move to left
|
|
|
- :left
|
|
|
- :right)]
|
|
|
- (p/let [_ (editor-handler/adjust-block-level! state direction)]
|
|
|
- (and input pos (js/setTimeout #(when-let [input (gdom/getElement input-id)]
|
|
|
- (util/move-cursor-to input pos))
|
|
|
- 0)))))))}
|
|
|
- (fn [e key-code]
|
|
|
- (let [key (gobj/get e "key")
|
|
|
- value (gobj/get input "value")
|
|
|
- pos (:pos (util/get-caret-pos input))]
|
|
|
- (cond
|
|
|
- (or
|
|
|
- (and (= key "#")
|
|
|
- (and
|
|
|
- (> pos 0)
|
|
|
- (= "#" (util/nth-safe value (dec pos)))))
|
|
|
- (and (= key " ")
|
|
|
- (state/get-editor-show-page-search-hashtag?)))
|
|
|
- (state/set-editor-show-page-search-hashtag! false)
|
|
|
-
|
|
|
- (and
|
|
|
- (not= key-code 8) ;; backspace
|
|
|
+ 9 (fn [state e]
|
|
|
+ (let [input-id (state/get-edit-input-id)
|
|
|
+ input (and input-id (gdom/getElement id))
|
|
|
+ pos (and input (:pos (util/get-caret-pos input)))]
|
|
|
+ (when-not (state/get-editor-show-input)
|
|
|
+ (util/stop e)
|
|
|
+ (let [direction (if (gobj/get e "shiftKey") ; shift+tab move to left
|
|
|
+ :left
|
|
|
+ :right)]
|
|
|
+ (p/let [_ (editor-handler/adjust-block-level! state direction)]
|
|
|
+ (and input pos (js/setTimeout #(when-let [input (gdom/getElement input-id)]
|
|
|
+ (util/move-cursor-to input pos))
|
|
|
+ 0)))))))}
|
|
|
+ {:not-matched-handler
|
|
|
+ (fn [e key-code]
|
|
|
+ (let [key (gobj/get e "key")
|
|
|
+ value (gobj/get input "value")
|
|
|
+ pos (:pos (util/get-caret-pos input))]
|
|
|
+ (cond
|
|
|
+ (or
|
|
|
+ (and (= key "#")
|
|
|
+ (and
|
|
|
+ (> pos 0)
|
|
|
+ (= "#" (util/nth-safe value (dec pos)))))
|
|
|
+ (and (= key " ")
|
|
|
+ (state/get-editor-show-page-search-hashtag?)))
|
|
|
+ (state/set-editor-show-page-search-hashtag! false)
|
|
|
+
|
|
|
(or
|
|
|
(editor-handler/surround-by? input "#" " ")
|
|
|
(editor-handler/surround-by? input "#" :end)
|
|
|
- (= key "#")))
|
|
|
- (do
|
|
|
- (commands/handle-step [:editor/search-page-hashtag])
|
|
|
- (state/set-last-pos! (:pos (util/get-caret-pos input)))
|
|
|
- (reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
|
|
-
|
|
|
- (and
|
|
|
- (= key " ")
|
|
|
- (state/get-editor-show-page-search-hashtag?))
|
|
|
- (state/set-editor-show-page-search-hashtag! false)
|
|
|
-
|
|
|
- (and
|
|
|
- (contains? (set/difference (set (keys editor-handler/reversed-autopair-map))
|
|
|
- #{"`"})
|
|
|
- key)
|
|
|
- (= (editor-handler/get-current-input-char input) key))
|
|
|
- (do
|
|
|
- (util/stop e)
|
|
|
- (util/cursor-move-forward input 1))
|
|
|
+ (= key "#"))
|
|
|
+ (do
|
|
|
+ (commands/handle-step [:editor/search-page-hashtag])
|
|
|
+ (state/set-last-pos! (:pos (util/get-caret-pos input)))
|
|
|
+ (reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
|
|
+
|
|
|
+ (and
|
|
|
+ (= key " ")
|
|
|
+ (state/get-editor-show-page-search-hashtag?))
|
|
|
+ (state/set-editor-show-page-search-hashtag! false)
|
|
|
+
|
|
|
+ (and
|
|
|
+ (contains? (set/difference (set (keys editor-handler/reversed-autopair-map))
|
|
|
+ #{"`"})
|
|
|
+ key)
|
|
|
+ (= (editor-handler/get-current-input-char input) key))
|
|
|
+ (do
|
|
|
+ (util/stop e)
|
|
|
+ (util/cursor-move-forward input 1))
|
|
|
|
|
|
- (contains? (set (keys editor-handler/autopair-map)) key)
|
|
|
- (do
|
|
|
- (util/stop e)
|
|
|
- (editor-handler/autopair input-id key format nil)
|
|
|
- (cond
|
|
|
- (editor-handler/surround-by? input "[[" "]]")
|
|
|
- (do
|
|
|
- (commands/handle-step [:editor/search-page])
|
|
|
- (reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
|
|
- (editor-handler/surround-by? input "((" "))")
|
|
|
- (do
|
|
|
- (commands/handle-step [:editor/search-block :reference])
|
|
|
- (reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
|
|
- :else
|
|
|
- nil))
|
|
|
-
|
|
|
- (let [sym "$"]
|
|
|
- (and (= key sym)
|
|
|
- (>= (count value) 1)
|
|
|
- (> pos 0)
|
|
|
- (= (nth value (dec pos)) sym)
|
|
|
- (if (> (count value) pos)
|
|
|
- (not= (nth value pos) sym)
|
|
|
- true)))
|
|
|
- (commands/simple-insert! input-id "$$" {:backward-pos 2})
|
|
|
-
|
|
|
- (let [sym "^"]
|
|
|
- (and (= key sym)
|
|
|
- (>= (count value) 1)
|
|
|
- (> pos 0)
|
|
|
- (= (nth value (dec pos)) sym)
|
|
|
- (if (> (count value) pos)
|
|
|
- (not= (nth value pos) sym)
|
|
|
- true)))
|
|
|
- (commands/simple-insert! input-id "^^" {:backward-pos 2})
|
|
|
-
|
|
|
- :else
|
|
|
- nil))))
|
|
|
+ (contains? (set (keys editor-handler/autopair-map)) key)
|
|
|
+ (do
|
|
|
+ (util/stop e)
|
|
|
+ (editor-handler/autopair input-id key format nil)
|
|
|
+ (cond
|
|
|
+ (editor-handler/surround-by? input "[[" "]]")
|
|
|
+ (do
|
|
|
+ (commands/handle-step [:editor/search-page])
|
|
|
+ (reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
|
|
+ (editor-handler/surround-by? input "((" "))")
|
|
|
+ (do
|
|
|
+ (commands/handle-step [:editor/search-block :reference])
|
|
|
+ (reset! commands/*slash-caret-pos (util/get-caret-pos input)))
|
|
|
+ :else
|
|
|
+ nil))
|
|
|
+
|
|
|
+ (let [sym "$"]
|
|
|
+ (and (= key sym)
|
|
|
+ (>= (count value) 1)
|
|
|
+ (> pos 0)
|
|
|
+ (= (nth value (dec pos)) sym)
|
|
|
+ (if (> (count value) pos)
|
|
|
+ (not= (nth value pos) sym)
|
|
|
+ true)))
|
|
|
+ (commands/simple-insert! input-id "$$" {:backward-pos 2})
|
|
|
+
|
|
|
+ (let [sym "^"]
|
|
|
+ (and (= key sym)
|
|
|
+ (>= (count value) 1)
|
|
|
+ (> pos 0)
|
|
|
+ (= (nth value (dec pos)) sym)
|
|
|
+ (if (> (count value) pos)
|
|
|
+ (not= (nth value pos) sym)
|
|
|
+ true)))
|
|
|
+ (commands/simple-insert! input-id "^^" {:backward-pos 2})
|
|
|
+
|
|
|
+ :else
|
|
|
+ nil)))})
|
|
|
(mixins/on-key-up
|
|
|
state
|
|
|
{}
|
|
|
@@ -676,7 +671,7 @@
|
|
|
(not (string/blank? value))
|
|
|
(not= (string/trim value) (string/trim content)))
|
|
|
(let [old-page-name (db/get-file-page path false)]
|
|
|
- (page-handler/rename-when-alter-title-propertiy! old-page-name path format content value)
|
|
|
+ (page-handler/rename-when-alter-title-property! old-page-name path format content value)
|
|
|
(file/alter-file (state/get-current-repo) path (string/trim value)
|
|
|
{:re-render-root? true}))))
|
|
|
(when-not (contains? #{:insert :indent-outdent} (state/get-editor-op))
|
|
|
@@ -685,24 +680,19 @@
|
|
|
[state {:keys [on-hide dummy? node format block block-parent-id]
|
|
|
:or {dummy? false}
|
|
|
:as option} id config]
|
|
|
- (let [content (state/sub [:editor/content id])]
|
|
|
- [:div.editor {:style {:position "relative"
|
|
|
- :display "flex"
|
|
|
- :flex "1 1 0%"}
|
|
|
- :class (if block "block-editor" "non-block-editor")}
|
|
|
+ (let [content (state/get-edit-content)]
|
|
|
+ [:div.editor-inner {:class (if block "block-editor" "non-block-editor")}
|
|
|
(when config/mobile? (mobile-bar state id))
|
|
|
- (ui/textarea
|
|
|
+ (ui/ls-textarea
|
|
|
{:id id
|
|
|
- :value (or content "")
|
|
|
+ :cacheMeasurements true
|
|
|
+ :default-value (or content "")
|
|
|
:minRows (if (state/enable-grammarly?) 2 1)
|
|
|
:on-click (fn [_e]
|
|
|
(let [input (gdom/getElement id)
|
|
|
current-pos (:pos (util/get-caret-pos input))]
|
|
|
(state/set-edit-pos! current-pos)
|
|
|
(editor-handler/close-autocomplete-if-outside input)))
|
|
|
- :on-key-down (fn [_e]
|
|
|
- (let [current-pos (:pos (util/get-caret-pos (gdom/getElement id)))]
|
|
|
- (state/set-edit-pos! current-pos)))
|
|
|
:on-change (fn [e]
|
|
|
(let [value (util/evalue e)
|
|
|
current-pos (:pos (util/get-caret-pos (gdom/getElement id)))]
|
|
|
@@ -716,8 +706,8 @@
|
|
|
;; TODO: is it cross-browser compatible?
|
|
|
(when (not= (gobj/get native-e "inputType") "insertFromPaste")
|
|
|
(when-let [matched-commands (seq (editor-handler/get-matched-commands input))]
|
|
|
- (reset! *slash-caret-pos (util/get-caret-pos input))
|
|
|
- (reset! *show-commands true)))
|
|
|
+ (reset! *slash-caret-pos (util/get-caret-pos input))
|
|
|
+ (reset! *show-commands true)))
|
|
|
"<"
|
|
|
(when-let [matched-commands (seq (editor-handler/get-matched-block-commands input))]
|
|
|
(reset! *angle-bracket-caret-pos (util/get-caret-pos input))
|