|
|
@@ -857,40 +857,9 @@
|
|
|
[]
|
|
|
(or (not @publishing?) (:publishing/enable-editing? (get-config))))
|
|
|
|
|
|
-(defn set-editing!
|
|
|
- ([edit-input-id content block cursor-range]
|
|
|
- (set-editing! edit-input-id content block cursor-range true))
|
|
|
- ([edit-input-id content block cursor-range move-cursor?]
|
|
|
- (when (and edit-input-id block
|
|
|
- (or
|
|
|
- (publishing-enable-editing?)
|
|
|
- (not @publishing?)))
|
|
|
- (let [block-element (gdom/getElement (string/replace edit-input-id "edit-block" "ls-block"))
|
|
|
- container (util/get-block-container block-element)
|
|
|
- block (if container
|
|
|
- (assoc block
|
|
|
- :block/container (gobj/get container "id"))
|
|
|
- block)
|
|
|
- content (string/trim (or content ""))]
|
|
|
- (swap! state
|
|
|
- (fn [state]
|
|
|
- (-> state
|
|
|
- (assoc-in [:editor/content edit-input-id] content)
|
|
|
- (assoc
|
|
|
- :editor/block block
|
|
|
- :editor/editing? {edit-input-id true}
|
|
|
- :editor/last-key-code nil
|
|
|
- :cursor-range cursor-range))))
|
|
|
- (when-let [input (gdom/getElement edit-input-id)]
|
|
|
- (let [pos (count cursor-range)]
|
|
|
- (when content
|
|
|
- (util/set-change-value input content))
|
|
|
-
|
|
|
- (when move-cursor?
|
|
|
- (cursor/move-cursor-to input pos))
|
|
|
-
|
|
|
- (when (or (util/mobile?) (mobile-util/native-platform?))
|
|
|
- (set-state! :mobile/show-action-bar? false))))))))
|
|
|
+(defn block-content-max-length
|
|
|
+ [repo]
|
|
|
+ (or (:block/content-max-length (get (sub-config) repo)) 5000))
|
|
|
|
|
|
(defn clear-edit!
|
|
|
[]
|
|
|
@@ -1543,6 +1512,47 @@
|
|
|
(clear-edit!)
|
|
|
(set-selection-blocks! blocks direction)))
|
|
|
|
|
|
+(defn set-editing!
|
|
|
+ ([edit-input-id content block cursor-range]
|
|
|
+ (set-editing! edit-input-id content block cursor-range true))
|
|
|
+ ([edit-input-id content block cursor-range move-cursor?]
|
|
|
+ (if (> (count content)
|
|
|
+ (block-content-max-length (get-current-repo)))
|
|
|
+ (let [elements (array-seq (js/document.getElementsByClassName (:block/uuid block)))]
|
|
|
+ (when (first elements)
|
|
|
+ (util/scroll-to-element (gobj/get (first elements) "id")))
|
|
|
+ (exit-editing-and-set-selected-blocks! elements))
|
|
|
+ (when (and edit-input-id block
|
|
|
+ (or
|
|
|
+ (publishing-enable-editing?)
|
|
|
+ (not @publishing?)))
|
|
|
+ (let [block-element (gdom/getElement (string/replace edit-input-id "edit-block" "ls-block"))
|
|
|
+ container (util/get-block-container block-element)
|
|
|
+ block (if container
|
|
|
+ (assoc block
|
|
|
+ :block/container (gobj/get container "id"))
|
|
|
+ block)
|
|
|
+ content (string/trim (or content ""))]
|
|
|
+ (swap! state
|
|
|
+ (fn [state]
|
|
|
+ (-> state
|
|
|
+ (assoc-in [:editor/content edit-input-id] content)
|
|
|
+ (assoc
|
|
|
+ :editor/block block
|
|
|
+ :editor/editing? {edit-input-id true}
|
|
|
+ :editor/last-key-code nil
|
|
|
+ :cursor-range cursor-range))))
|
|
|
+ (when-let [input (gdom/getElement edit-input-id)]
|
|
|
+ (let [pos (count cursor-range)]
|
|
|
+ (when content
|
|
|
+ (util/set-change-value input content))
|
|
|
+
|
|
|
+ (when move-cursor?
|
|
|
+ (cursor/move-cursor-to input pos))
|
|
|
+
|
|
|
+ (when (or (util/mobile?) (mobile-util/native-platform?))
|
|
|
+ (set-state! :mobile/show-action-bar? false)))))))))
|
|
|
+
|
|
|
(defn remove-watch-state [key]
|
|
|
(remove-watch state key))
|
|
|
|