Browse Source

Merge branch 'feat/outliner-core' of github.com:logseq/logseq into feat/outliner-core

Tienson Qin 4 years ago
parent
commit
fe5df9ca36

+ 0 - 27
src/main/frontend/handler/editor.cljs

@@ -1149,33 +1149,6 @@
        (text/remove-properties! format)
        string/trim))
 
-(defn on-up-down
-  [direction]
-  (when (state/editing?)
-    (let [edit-block (state/get-edit-block)
-          {:block/keys [uuid content format]} edit-block
-          element (state/get-input)
-          line-height (util/get-textarea-line-height element)
-          repo (state/get-current-repo)
-          up? (= :up direction)]
-      (if (or (and up? (util/textarea-cursor-first-row? element line-height))
-              (and (not up?) (util/textarea-cursor-end-row? element line-height)))
-        (do
-          (let [f (if up? get-prev-block-non-collapsed get-next-block-non-collapsed)
-                sibling-block (f (gdom/getElement (state/get-editing-block-dom-id)))]
-            (when sibling-block
-              (when-let [sibling-block-id (dom/attr sibling-block "blockid")]
-                (let [value (state/get-edit-content)]
-                  (when (not= (clean-content! format content)
-                              (string/trim value))
-                    (save-block! repo uuid value)))
-                (let [block (db/pull repo '[*] [:block/uuid (cljs.core/uuid sibling-block-id)])]
-                  (edit-block! block [direction (util/get-first-or-last-line-pos element)] format (state/get-edit-input-id)))))))
-        ;;just up and down
-        (if up?
-          (util/move-cursor-up element)
-          (util/move-cursor-down element))))))
-
 (defn insert-command!
   [id command-output format {:keys [restore?]
                              :or {restore? true}

+ 1 - 1
src/main/frontend/modules/shortcut/binding.cljc

@@ -28,7 +28,7 @@
    :editor/bold "mod+b"
    :editor/italics "mod+i"
    :editor/highlight "mod+shift+h"
-   :editor/insert-link "mod+shift+i"
+   :editor/insert-link "mod+shift+k"
    :editor/select-all-blocks "mod+shift+a"
    :editor/move-block-up (if mac? "mod+shift+up"  "alt+shift+up")
    :editor/move-block-down (if mac? "mod+shift+down" "alt+shift+down")

+ 6 - 0
src/main/frontend/state.cljs

@@ -723,6 +723,12 @@
        (when-let [input (gdom/getElement edit-input-id)]
          (let [pos (count cursor-range)]
            (when content
+             (util/set-change-value input content)
+             ;; FIXME
+             ;; use set-change-value for now
+             ;; until somebody can figure out why set! value doesn't work here
+             ;; it seems to me textarea autoresize is completely broken
+             #_
              (set! (.-value input) (string/trim content)))
            (when move-cursor?
              (util/move-cursor-to input pos))))))))

+ 44 - 42
src/main/frontend/util.cljc

@@ -1014,48 +1014,50 @@
 (def bare-marker-pattern
   #"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")
 
-(defn add-or-update-marker
-  [content format marker]
-  (let [[re-pattern new-line-re-pattern]
-        (if (= :org format)
-          [#"\*+\s" #"\n\*+\s"]
-          [#"#+\s" #"\n#+\s"])
-        pos
-        (if-let [matches (seq (re-pos new-line-re-pattern content))]
-          (let [[start-pos content] (last matches)]
-            (+ start-pos (count content)))
-          (count (re-find re-pattern content)))
-        new-content
-        (str (subs content 0 pos)
-             (string/replace-first (subs content pos)
-                                   marker-pattern
-                                   (str marker " ")))]
-    new-content))
-
-(defn add-or-update-priority
-  [content format priority]
-  (let [priority-pattern  #"(\[#[ABC]\])?\s?"
-        [re-pattern new-line-re-pattern]
-        (if (= :org format)
-          [#"\*+\s" #"\n\*+\s"]
-          [#"#+\s" #"\n#+\s"])
-        skip-hash-pos
-        (if-let [matches (seq (re-pos new-line-re-pattern content))]
-          (let [[start-pos content] (last matches)]
-            (+ start-pos (count content)))
-          (count (re-find re-pattern content)))
-        skip-marker-pos
-        (if-let [matches (seq (re-pos bare-marker-pattern (subs content skip-hash-pos)))]
-          (let [[start-pos content] (last matches)]
-            (+ start-pos (count content)))
-          0)
-        pos (+ skip-hash-pos skip-marker-pos)
-        new-content
-        (str (subs content 0 pos)
-             (string/replace-first (subs content pos)
-                                   priority-pattern
-                                   (str priority " ")))]
-    new-content))
+#?(:cljs
+   (defn add-or-update-marker
+     [content format marker]
+     (let [[re-pattern new-line-re-pattern]
+           (if (= :org format)
+             [#"\*+\s" #"\n\*+\s"]
+             [#"#+\s" #"\n#+\s"])
+           pos
+           (if-let [matches (seq (re-pos new-line-re-pattern content))]
+             (let [[start-pos content] (last matches)]
+               (+ start-pos (count content)))
+             (count (re-find re-pattern content)))
+           new-content
+           (str (subs content 0 pos)
+                (string/replace-first (subs content pos)
+                                      marker-pattern
+                                      (str marker " ")))]
+       new-content)))
+
+#?(:cljs
+   (defn add-or-update-priority
+     [content format priority]
+     (let [priority-pattern  #"(\[#[ABC]\])?\s?"
+           [re-pattern new-line-re-pattern]
+           (if (= :org format)
+             [#"\*+\s" #"\n\*+\s"]
+             [#"#+\s" #"\n#+\s"])
+           skip-hash-pos
+           (if-let [matches (seq (re-pos new-line-re-pattern content))]
+             (let [[start-pos content] (last matches)]
+               (+ start-pos (count content)))
+             (count (re-find re-pattern content)))
+           skip-marker-pos
+           (if-let [matches (seq (re-pos bare-marker-pattern (subs content skip-hash-pos)))]
+             (let [[start-pos content] (last matches)]
+               (+ start-pos (count content)))
+             0)
+           pos (+ skip-hash-pos skip-marker-pos)
+           new-content
+           (str (subs content 0 pos)
+                (string/replace-first (subs content pos)
+                                      priority-pattern
+                                      (str priority " ")))]
+       new-content)))
 
 (defn pp-str [x]
   (with-out-str (clojure.pprint/pprint x)))