mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 02:16:30 +00:00
fix slash command clashes with Org-mode italics (#3010)
* enhance: fix https://github.com/logseq/logseq/issues/990 Co-authored-by: leizhe <leizhe@leizhedeMacBook-Air.local>
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
(defn- get-selection-and-format
|
||||
[]
|
||||
(when-let [block (state/get-edit-block)]
|
||||
(when-let [id (:block/uuid block)]
|
||||
(when (:block/uuid block)
|
||||
(when-let [edit-id (state/get-edit-input-id)]
|
||||
(when-let [input (gdom/getElement edit-id)]
|
||||
{:selection-start (gobj/get input "selectionStart")
|
||||
@@ -76,7 +76,7 @@
|
||||
(defn- format-text!
|
||||
[pattern-fn]
|
||||
(when-let [m (get-selection-and-format)]
|
||||
(let [{:keys [selection-start selection-end format value block edit-id input]} m
|
||||
(let [{:keys [selection-start selection-end format value edit-id input]} m
|
||||
empty-selection? (= selection-start selection-end)
|
||||
pattern (pattern-fn format)
|
||||
pattern-count (count pattern)
|
||||
@@ -104,7 +104,7 @@
|
||||
(defn italics-format! []
|
||||
(format-text! config/get-italic))
|
||||
|
||||
(defn highlight-format! [state]
|
||||
(defn highlight-format! []
|
||||
(when-let [block (state/get-edit-block)]
|
||||
(let [format (:block/format block)]
|
||||
(format-text! #(config/get-highlight format)))))
|
||||
@@ -114,7 +114,7 @@
|
||||
|
||||
(defn html-link-format! []
|
||||
(when-let [m (get-selection-and-format)]
|
||||
(let [{:keys [selection-start selection-end format value block edit-id input]} m
|
||||
(let [{:keys [selection-start selection-end format value edit-id input]} m
|
||||
cur-pos (cursor/pos input)
|
||||
empty-selection? (= selection-start selection-end)
|
||||
selection (subs value selection-start selection-end)
|
||||
@@ -207,9 +207,9 @@
|
||||
|
||||
;; id: block dom id, "ls-block-counter-uuid"
|
||||
(defn edit-block!
|
||||
([block pos format id]
|
||||
(edit-block! block pos format id nil))
|
||||
([block pos format id {:keys [custom-content tail-len move-cursor?]
|
||||
([block pos id]
|
||||
(edit-block! block pos id nil))
|
||||
([block pos id {:keys [custom-content tail-len move-cursor?]
|
||||
:or {tail-len 0
|
||||
move-cursor? true}}]
|
||||
(when-not config/publishing?
|
||||
@@ -245,7 +245,6 @@
|
||||
(edit-block!
|
||||
last-block
|
||||
pos
|
||||
(:block/format last-block)
|
||||
(string/replace (gobj/get first-block "id")
|
||||
"ls-block"
|
||||
"edit-block"))))
|
||||
@@ -495,48 +494,47 @@
|
||||
;; FIXME: painful
|
||||
(defn update-cache-for-block-insert!
|
||||
"Currently, this only affects current editor container to improve the performance."
|
||||
[repo config {:block/keys [page uuid] :as block} blocks]
|
||||
[repo config {:block/keys [page uuid] :as _block} blocks]
|
||||
(let [blocks (map :data blocks)
|
||||
[first-block last-block right-block] blocks
|
||||
child? (= (first (:block/parent last-block))
|
||||
(:block/uuid first-block))
|
||||
blocks-container-id (when-let [id (:id config)]
|
||||
(and (util/uuid-string? id) (medley/uuid id)))]
|
||||
(let [new-last-block (let [first-block-uuid (:block/uuid (db/entity (:db/id first-block)))
|
||||
first-block-id {:db/id (:db/id first-block)}]
|
||||
(and (util/uuid-string? id) (medley/uuid id)))
|
||||
new-last-block (let [first-block-id {:db/id (:db/id first-block)}]
|
||||
(assoc last-block
|
||||
:block/left first-block-id
|
||||
:block/parent (if child?
|
||||
first-block-id
|
||||
;; sibling
|
||||
(:block/parent first-block))))
|
||||
blocks [first-block new-last-block]
|
||||
blocks-atom (if blocks-container-id
|
||||
(db/get-block-blocks-cache-atom repo blocks-container-id)
|
||||
(db/get-page-blocks-cache-atom repo (:db/id page)))
|
||||
[before-part after-part] (and blocks-atom
|
||||
(split-with
|
||||
#(not= uuid (:block/uuid %))
|
||||
@blocks-atom))
|
||||
after-part (rest after-part)
|
||||
blocks (concat before-part blocks after-part)
|
||||
blocks (if right-block
|
||||
(map (fn [block]
|
||||
(if (= (:block/uuid right-block) (:block/uuid block))
|
||||
(assoc block :block/left (:block/left right-block))
|
||||
block)) blocks)
|
||||
blocks)]
|
||||
(when blocks-atom
|
||||
(reset! blocks-atom blocks)))))
|
||||
blocks [first-block new-last-block]
|
||||
blocks-atom (if blocks-container-id
|
||||
(db/get-block-blocks-cache-atom repo blocks-container-id)
|
||||
(db/get-page-blocks-cache-atom repo (:db/id page)))
|
||||
[before-part after-part] (and blocks-atom
|
||||
(split-with
|
||||
#(not= uuid (:block/uuid %))
|
||||
@blocks-atom))
|
||||
after-part (rest after-part)
|
||||
blocks (concat before-part blocks after-part)
|
||||
blocks (if right-block
|
||||
(map (fn [block]
|
||||
(if (= (:block/uuid right-block) (:block/uuid block))
|
||||
(assoc block :block/left (:block/left right-block))
|
||||
block)) blocks)
|
||||
blocks)]
|
||||
(when blocks-atom
|
||||
(reset! blocks-atom blocks))))
|
||||
|
||||
(defn insert-new-block-before-block-aux!
|
||||
[config
|
||||
{:block/keys [uuid content repo format page]
|
||||
{:block/keys [repo]
|
||||
db-id :db/id
|
||||
:as block}
|
||||
value
|
||||
{:keys [ok-handler]
|
||||
:as opts}]
|
||||
:as _opts}]
|
||||
(let [input (gdom/getElement (state/get-edit-input-id))
|
||||
pos (cursor/pos input)
|
||||
repo (or repo (state/get-current-repo))
|
||||
@@ -561,12 +559,12 @@
|
||||
|
||||
(defn insert-new-block-aux!
|
||||
[config
|
||||
{:block/keys [uuid content repo format page]
|
||||
{:block/keys [uuid repo]
|
||||
db-id :db/id
|
||||
:as block}
|
||||
value
|
||||
{:keys [ok-handler]
|
||||
:as opts}]
|
||||
:as _opts}]
|
||||
(let [block-self? (block-self-alone-when-insert? config uuid)
|
||||
input (gdom/getElement (state/get-edit-input-id))
|
||||
pos (cursor/pos input)
|
||||
@@ -590,8 +588,7 @@
|
||||
(let [opts {:key :block/insert
|
||||
:data [current-block next-block]}]
|
||||
(db/refresh! repo opts)))]
|
||||
(do
|
||||
(if (or (:ref? config)
|
||||
(if (or (:ref? config)
|
||||
(not sibling?)
|
||||
zooming?)
|
||||
(refresh-fn)
|
||||
@@ -601,7 +598,7 @@
|
||||
;; WORKAROUND: The block won't refresh itself even if the content is empty.
|
||||
(when block-self?
|
||||
(gobj/set input "value" ""))
|
||||
(profile "ok handler" (ok-handler next-block)))))
|
||||
(profile "ok handler" (ok-handler next-block))))
|
||||
|
||||
(defn clear-when-saved!
|
||||
[]
|
||||
@@ -640,16 +637,14 @@
|
||||
(not= :insert (state/get-editor-op)))
|
||||
(state/set-editor-op! :insert)
|
||||
(when-let [state (get-state)]
|
||||
(let [{:keys [block value format id config]} state
|
||||
(let [{:keys [block value id config]} state
|
||||
value (if (string? block-value) block-value value)
|
||||
block-id (:block/uuid block)
|
||||
block (or (db/pull [:block/uuid block-id])
|
||||
block)
|
||||
repo (or (:block/repo block) (state/get-current-repo))
|
||||
block-self? (block-self-alone-when-insert? config block-id)
|
||||
input (gdom/getElement (state/get-edit-input-id))
|
||||
pos (cursor/pos input)
|
||||
repo (or repo (state/get-current-repo))
|
||||
[fst-block-text snd-block-text] (compute-fst-snd-block-text value pos)
|
||||
insert-fn (match (mapv boolean [block-self? (seq fst-block-text) (seq snd-block-text)])
|
||||
[true _ _] insert-new-block-aux!
|
||||
@@ -658,7 +653,7 @@
|
||||
(insert-fn config block value
|
||||
{:ok-handler
|
||||
(fn [last-block]
|
||||
(edit-block! last-block 0 format id)
|
||||
(edit-block! last-block 0 id)
|
||||
(clear-when-saved!))}))))
|
||||
(state/set-editor-op! nil)))
|
||||
|
||||
@@ -674,8 +669,7 @@
|
||||
(db/entity [:block/name (string/lower-case page)])
|
||||
(db/entity [:block/uuid block-uuid]))]
|
||||
(when block
|
||||
(let [repo (state/get-current-repo)
|
||||
last-block (when (not sibling?)
|
||||
(let [last-block (when (not sibling?)
|
||||
(let [children (:block/_parent block)
|
||||
blocks (db/sort-by-left children block)
|
||||
last-block-id (:db/id (last blocks))]
|
||||
@@ -698,8 +692,8 @@
|
||||
(:db/id (:block/page new-block))))
|
||||
new-block (-> new-block
|
||||
(wrap-parse-block)
|
||||
(assoc :block/uuid (or custom-uuid (db/new-block-id))))]
|
||||
(let [[block-m sibling?] (cond
|
||||
(assoc :block/uuid (or custom-uuid (db/new-block-id))))
|
||||
[block-m sibling?] (cond
|
||||
before?
|
||||
(let [block (db/pull (:db/id (:block/left block)))
|
||||
sibling? (if (:block/name block) false sibling?)]
|
||||
@@ -717,10 +711,11 @@
|
||||
;; FIXME: assert
|
||||
:else
|
||||
nil)]
|
||||
(when block-m
|
||||
(outliner-insert-block! {:skip-save-current-block? true} block-m new-block sibling?)
|
||||
(when re-render-root? (ui-handler/re-render-root!))
|
||||
new-block)))))))
|
||||
|
||||
(when block-m
|
||||
(outliner-insert-block! {:skip-save-current-block? true} block-m new-block sibling?)
|
||||
(when re-render-root? (ui-handler/re-render-root!))
|
||||
new-block))))))
|
||||
|
||||
(defn insert-first-page-block-if-not-exists!
|
||||
[page-name]
|
||||
@@ -816,7 +811,7 @@
|
||||
content))
|
||||
|
||||
(defn check
|
||||
[{:block/keys [uuid marker content format repeated?] :as block}]
|
||||
[{:block/keys [marker content repeated?] :as block}]
|
||||
(let [new-content (string/replace-first content marker "DONE")
|
||||
new-content (if repeated?
|
||||
(update-timestamps-content! block content)
|
||||
@@ -824,7 +819,7 @@
|
||||
(save-block-if-changed! block new-content)))
|
||||
|
||||
(defn uncheck
|
||||
[{:block/keys [uuid marker content format] :as block}]
|
||||
[{:block/keys [content] :as block}]
|
||||
(let [marker (if (= :now (state/get-preferred-workflow))
|
||||
"LATER"
|
||||
"TODO")
|
||||
@@ -833,18 +828,18 @@
|
||||
|
||||
(defn cycle-todo!
|
||||
[]
|
||||
(when-let [block (state/get-edit-block)]
|
||||
(when (state/get-edit-block)
|
||||
(let [edit-input-id (state/get-edit-input-id)
|
||||
current-input (gdom/getElement edit-input-id)
|
||||
content (state/get-edit-content)
|
||||
format (or (db/get-page-format (state/get-current-page))
|
||||
(state/get-preferred-format))
|
||||
[new-content marker] (marker/cycle-marker content format (state/get-preferred-workflow))
|
||||
new-content (string/triml new-content)]
|
||||
(let [new-pos (commands/compute-pos-delta-when-change-marker
|
||||
content marker (cursor/pos current-input))]
|
||||
(state/set-edit-content! edit-input-id new-content)
|
||||
(cursor/move-cursor-to current-input new-pos)))))
|
||||
new-content (string/triml new-content)
|
||||
new-pos (commands/compute-pos-delta-when-change-marker
|
||||
content marker (cursor/pos current-input))]
|
||||
(state/set-edit-content! edit-input-id new-content)
|
||||
(cursor/move-cursor-to current-input new-pos))))
|
||||
|
||||
(defn set-marker
|
||||
[{:block/keys [marker content] :as block} new-marker]
|
||||
@@ -867,8 +862,7 @@
|
||||
(defn cycle-todos!
|
||||
[]
|
||||
(when-let [blocks (seq (get-selected-blocks-with-children))]
|
||||
(let [repo (state/get-current-repo)
|
||||
workflow (state/get-preferred-workflow)
|
||||
(let [workflow (state/get-preferred-workflow)
|
||||
ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
|
||||
(uuid id)) blocks))
|
||||
(remove nil?))]
|
||||
@@ -879,14 +873,14 @@
|
||||
(set-marker block new-marker))))))
|
||||
|
||||
(defn set-priority
|
||||
[{:block/keys [uuid marker priority content] :as block} new-priority]
|
||||
[{:block/keys [priority content] :as block} new-priority]
|
||||
(let [new-content (string/replace-first content
|
||||
(util/format "[#%s]" priority)
|
||||
(util/format "[#%s]" new-priority))]
|
||||
(save-block-if-changed! block new-content)))
|
||||
|
||||
(defn delete-block-aux!
|
||||
[{:block/keys [uuid content repo refs] :as block} children?]
|
||||
[{:block/keys [uuid repo] :as _block} children?]
|
||||
(let [repo (or repo (state/get-current-repo))
|
||||
block (db/pull repo '[*] [:block/uuid uuid])]
|
||||
(when block
|
||||
@@ -910,15 +904,15 @@
|
||||
(utf8/length (utf8/encode original-content))
|
||||
0)
|
||||
0)]
|
||||
(edit-block! block pos format id
|
||||
(edit-block! block pos id
|
||||
{:custom-content new-value
|
||||
:tail-len tail-len
|
||||
:move-cursor? false}))))))
|
||||
|
||||
(defn delete-block!
|
||||
([repo e]
|
||||
(delete-block! repo e true))
|
||||
([repo e delete-children?]
|
||||
([repo]
|
||||
(delete-block! repo true))
|
||||
([repo delete-children?]
|
||||
(state/set-editor-op! :delete)
|
||||
(let [{:keys [id block-id block-parent-id value format]} (get-state)]
|
||||
(when block-id
|
||||
@@ -958,7 +952,7 @@
|
||||
[blocks]
|
||||
(if (<= (count blocks) 1)
|
||||
blocks
|
||||
(let [[f s & others] blocks]
|
||||
(let [[f s & _others] blocks]
|
||||
(if (or
|
||||
(= (:block/left s) {:db/id (:db/id f)})
|
||||
(let [parents (db/get-block-parents (state/get-current-repo)
|
||||
@@ -1026,7 +1020,6 @@
|
||||
(when (= (:block/uuid editing-block) block-id)
|
||||
(edit-block! editing-block
|
||||
input-pos
|
||||
format
|
||||
(state/get-edit-input-id)))))))))
|
||||
|
||||
(defn remove-block-property!
|
||||
@@ -1062,7 +1055,7 @@
|
||||
key (string/lower-case (str key))
|
||||
value (str value)]
|
||||
(when-let [block (db/pull [:block/uuid block-id])]
|
||||
(let [{:block/keys [content scheduled deadline format]} block
|
||||
(let [{:block/keys [content]} block
|
||||
content (or (state/get-edit-content) content)
|
||||
new-content (-> (text/remove-timestamp content key)
|
||||
(text/add-timestamp key value))]
|
||||
@@ -1078,7 +1071,8 @@
|
||||
(set-block-property! block-id "id" (str block-id)))))
|
||||
|
||||
(defn copy-block-ref!
|
||||
([block-id] (copy-block-ref! block-id #(str %)))
|
||||
([block-id]
|
||||
(copy-block-ref! block-id #(str %)))
|
||||
([block-id tap-clipboard]
|
||||
(set-block-id! block-id)
|
||||
(util/copy-to-clipboard! (tap-clipboard block-id))))
|
||||
@@ -1138,8 +1132,6 @@
|
||||
(vec (tree/sort-blocks (db/get-block-children repo (:block/uuid b)) b))
|
||||
[b])) blocks))
|
||||
block-ids* (mapv :block/uuid blocks*)
|
||||
unordered? (:block/unordered (first blocks*))
|
||||
format (:block/format (first blocks*))
|
||||
level-blocks-map (blocks-with-level blocks*)
|
||||
level-blocks-uuid-map (into {} (mapv (fn [b] [(:block/uuid b) b]) (vals level-blocks-map)))
|
||||
level-blocks (mapv (fn [uuid] (get level-blocks-uuid-map uuid)) block-ids*)
|
||||
@@ -1167,8 +1159,7 @@
|
||||
(defn copy-block-refs
|
||||
[]
|
||||
(when-let [blocks (seq (get-selected-blocks-with-children))]
|
||||
(let [repo (state/get-current-repo)
|
||||
ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
|
||||
(let [ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
|
||||
(uuid id)) blocks))
|
||||
(remove nil?))
|
||||
ids-str (some->> ids
|
||||
@@ -1219,7 +1210,7 @@
|
||||
(defn- get-nearest-page
|
||||
[]
|
||||
(when-let [block (state/get-edit-block)]
|
||||
(when-let [id (:block/uuid block)]
|
||||
(when (:block/uuid block)
|
||||
(when-let [edit-id (state/get-edit-input-id)]
|
||||
(when-let [input (gdom/getElement edit-id)]
|
||||
(when-let [pos (cursor/pos input)]
|
||||
@@ -1254,8 +1245,7 @@
|
||||
(let [page-name (string/lower-case page)]
|
||||
(state/clear-edit!)
|
||||
(insert-first-page-block-if-not-exists! page-name)
|
||||
(route-handler/redirect! {:to :page
|
||||
:path-params {:name page-name}})))))
|
||||
(route-handler/redirect-to-page! page-name)))))
|
||||
|
||||
(defn open-link-in-sidebar!
|
||||
[]
|
||||
@@ -1283,10 +1273,10 @@
|
||||
db/entity
|
||||
:block/uuid)]
|
||||
(let [pos (state/get-edit-pos)]
|
||||
(route-handler/redirect! {:to :page
|
||||
:path-params {:name (str id)}})
|
||||
(route-handler/redirect-to-page! id)
|
||||
(edit-block! {:block/uuid id} pos nil id)))
|
||||
(js/window.history.forward)))
|
||||
|
||||
(defn zoom-out!
|
||||
[]
|
||||
(if (state/editing?)
|
||||
@@ -1301,18 +1291,16 @@
|
||||
(nil? (:block/name block-parent))
|
||||
(:block/uuid block-parent))]
|
||||
(do
|
||||
(route-handler/redirect! {:to :page
|
||||
:path-params {:name (str id)}})
|
||||
(route-handler/redirect-to-page! id)
|
||||
|
||||
(edit-block! {:block/uuid block-id} :max nil block-id))
|
||||
(edit-block! {:block/uuid block-id} :max block-id))
|
||||
(let [page-id (some-> (db/entity [:block/uuid block-id])
|
||||
:block/page
|
||||
:db/id)]
|
||||
|
||||
(when-let [page-name (:block/name (db/entity page-id))]
|
||||
(route-handler/redirect! {:to :page
|
||||
:path-params {:name page-name}})
|
||||
(edit-block! {:block/uuid block-id} :max nil block-id)))))))
|
||||
(route-handler/redirect-to-page! page-name)
|
||||
(edit-block! {:block/uuid block-id} :max block-id)))))))
|
||||
(js/window.history.back)))
|
||||
|
||||
(defn cut-block!
|
||||
@@ -1352,7 +1340,7 @@
|
||||
|
||||
(defn on-select-block
|
||||
[direction]
|
||||
(fn [e]
|
||||
(fn [_event]
|
||||
(cond
|
||||
;; when editing, quit editing and select current block
|
||||
(state/editing?)
|
||||
@@ -1378,7 +1366,7 @@
|
||||
(clear-last-selected-block!))))
|
||||
|
||||
(defn save-block-aux!
|
||||
[block value format opts]
|
||||
[block value opts]
|
||||
(let [value (string/trim value)]
|
||||
;; FIXME: somehow frontend.components.editor's will-unmount event will loop forever
|
||||
;; maybe we shouldn't save the block/file in "will-unmount" event?
|
||||
@@ -1394,9 +1382,9 @@
|
||||
(db-model/query-block-by-uuid block-or-uuid) block-or-uuid)
|
||||
format (:block/format block)]
|
||||
(save-block! {:block block :repo repo :format format} content)))
|
||||
([{:keys [format block repo] :as state} value]
|
||||
([{:keys [block repo] :as _state} value]
|
||||
(when (:db/id (db/entity repo [:block/uuid (:block/uuid block)]))
|
||||
(save-block-aux! block value format {}))))
|
||||
(save-block-aux! block value {}))))
|
||||
|
||||
(defn save-current-block!
|
||||
([]
|
||||
@@ -1404,7 +1392,7 @@
|
||||
([{:keys [force?] :as opts}]
|
||||
;; non English input method
|
||||
(when-not (state/editor-in-composition?)
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(when (state/get-current-repo)
|
||||
(when (and (not @commands/*show-commands)
|
||||
(not @commands/*show-block-commands)
|
||||
(not (state/get-editor-show-page-search?))
|
||||
@@ -1425,13 +1413,12 @@
|
||||
value (and elem (gobj/get elem "value"))]
|
||||
(cond
|
||||
force?
|
||||
(save-block-aux! db-block value (:block/format db-block) opts)
|
||||
(save-block-aux! db-block value opts)
|
||||
|
||||
(and block value db-content-without-heading
|
||||
(or
|
||||
(not= (string/trim db-content-without-heading)
|
||||
(string/trim value))))
|
||||
(save-block-aux! db-block value (:block/format db-block) opts)))
|
||||
(not= (string/trim db-content-without-heading)
|
||||
(string/trim value)))
|
||||
(save-block-aux! db-block value opts)))
|
||||
(catch js/Error error
|
||||
(log/error :save-block-failed error))))))))
|
||||
|
||||
@@ -1508,24 +1495,23 @@
|
||||
([repo dir path files gen-filename]
|
||||
(p/all
|
||||
(for [[index ^js file] (map-indexed vector files)]
|
||||
(do
|
||||
;; WARN file name maybe fully qualified path when paste file
|
||||
(let [file-name (util/node-path.basename (.-name file))
|
||||
[file-base ext] (if file-name
|
||||
(let [last-dot-index (string/last-index-of file-name ".")]
|
||||
[(subs file-name 0 last-dot-index)
|
||||
(subs file-name last-dot-index)])
|
||||
["" ""])
|
||||
filename (str (gen-filename index file-base) ext)
|
||||
;; WARN file name maybe fully qualified path when paste file
|
||||
(let [file-name (util/node-path.basename (.-name file))
|
||||
[file-base ext] (if file-name
|
||||
(let [last-dot-index (string/last-index-of file-name ".")]
|
||||
[(subs file-name 0 last-dot-index)
|
||||
(subs file-name last-dot-index)])
|
||||
["" ""])
|
||||
filename (str (gen-filename index file-base) ext)
|
||||
filename (str path "/" filename)]
|
||||
;(js/console.debug "Write asset #" dir filename file)
|
||||
(if (util/electron?)
|
||||
(let [from (.-path file)
|
||||
from (if (string/blank? from) nil from)]
|
||||
(p/then (js/window.apis.copyFileToAssets dir filename from)
|
||||
#(p/resolved [filename (if (string? %) (js/File. #js[] %) file) (.join util/node-path dir filename)])))
|
||||
(if (util/electron?)
|
||||
(let [from (.-path file)
|
||||
from (if (string/blank? from) nil from)]
|
||||
(p/then (js/window.apis.copyFileToAssets dir filename from)
|
||||
#(p/resolved [filename (if (string? %) (js/File. #js[] %) file) (.join util/node-path dir filename)])))
|
||||
(p/then (fs/write-file! repo dir filename (.stream file) nil)
|
||||
#(p/resolved [filename file])))))))))
|
||||
#(p/resolved [filename file]))))))))
|
||||
|
||||
(defonce *assets-url-cache (atom {}))
|
||||
|
||||
@@ -1536,7 +1522,7 @@
|
||||
(cond
|
||||
(util/electron?)
|
||||
(str "assets://" repo-dir path)
|
||||
|
||||
|
||||
(mobile/is-native-platform?)
|
||||
(mobile/convert-file-src
|
||||
(str "file://" repo-dir path))
|
||||
@@ -1554,10 +1540,9 @@
|
||||
url))))))))
|
||||
|
||||
(defn delete-asset-of-block!
|
||||
[{:keys [repo href title full-text block-id local? delete-local?] :as opts}]
|
||||
[{:keys [repo href full-text block-id local? delete-local?] :as _opts}]
|
||||
(let [block (db-model/query-block-by-uuid block-id)
|
||||
_ (or block (throw (str block-id " not exists")))
|
||||
format (:block/format block)
|
||||
text (:block/content block)
|
||||
content (string/replace text full-text "")]
|
||||
(save-block! repo block content)
|
||||
@@ -1641,6 +1626,8 @@
|
||||
"_" "_"
|
||||
"^" "^"
|
||||
"=" "="
|
||||
"/" "/"
|
||||
"+" "+"
|
||||
;; ":" ":" ; TODO: only properties editing and org mode tag
|
||||
})
|
||||
|
||||
@@ -1648,8 +1635,8 @@
|
||||
(zipmap (vals autopair-map)
|
||||
(keys autopair-map)))
|
||||
|
||||
(defonce autopair-when-selected
|
||||
#{"^" "_" "="})
|
||||
(def autopair-when-selected
|
||||
#{"*" "^" "_" "=" "+" "/"})
|
||||
|
||||
(def delete-map
|
||||
(assoc autopair-map
|
||||
@@ -1663,7 +1650,7 @@
|
||||
(defn autopair
|
||||
[input-id prefix format {:keys [restore?]
|
||||
:or {restore? true}
|
||||
:as option}]
|
||||
:as _option}]
|
||||
(let [value (get autopair-map prefix)
|
||||
selected (util/get-selected-text)
|
||||
postfix (str selected value)
|
||||
@@ -1671,7 +1658,7 @@
|
||||
input (gdom/getElement input-id)]
|
||||
(when value
|
||||
(when-not (string/blank? selected) (reset! *selected-text selected))
|
||||
(let [[prefix pos] (commands/simple-replace! input-id value selected
|
||||
(let [[prefix _pos] (commands/simple-replace! input-id value selected
|
||||
{:backward-pos (count postfix)
|
||||
:check-fn (fn [new-value prefix-pos]
|
||||
(when (>= prefix-pos 0)
|
||||
@@ -1717,12 +1704,12 @@
|
||||
(let [block (state/get-edit-block)
|
||||
editing-page (and block
|
||||
(when-let [page-id (:db/id (:block/page block))]
|
||||
(:block/name (db/entity page-id))))]
|
||||
(let [pages (search/page-search q 20)]
|
||||
(if editing-page
|
||||
;; To prevent self references
|
||||
(remove (fn [p] (= (string/lower-case p) editing-page)) pages)
|
||||
pages))))
|
||||
(:block/name (db/entity page-id))))
|
||||
pages (search/page-search q 20)]
|
||||
(if editing-page
|
||||
;; To prevent self references
|
||||
(remove (fn [p] (= (string/lower-case p) editing-page)) pages)
|
||||
pages)))
|
||||
|
||||
(defn get-matched-blocks
|
||||
[q block-id]
|
||||
@@ -1776,7 +1763,7 @@
|
||||
(commands/get-matched-commands
|
||||
last-command
|
||||
(commands/block-commands-map))))))
|
||||
(catch js/Error e
|
||||
(catch js/Error _error
|
||||
nil)))
|
||||
|
||||
(defn auto-complete?
|
||||
@@ -1830,7 +1817,7 @@
|
||||
|
||||
(defn move-up-down
|
||||
[up?]
|
||||
(fn [e]
|
||||
(fn [_event]
|
||||
(when-let [block-id (:block/uuid (state/get-edit-block))]
|
||||
(when-let [block (db/pull [:block/uuid block-id])]
|
||||
(outliner-core/move-node (outliner-core/block block) up?)
|
||||
@@ -1896,7 +1883,7 @@
|
||||
:org (util/format "[[%s]]"))))
|
||||
|
||||
(defn handle-command-input
|
||||
[command id format m pos]
|
||||
[command id format m]
|
||||
(case command
|
||||
:link
|
||||
(let [{:keys [link label]} m]
|
||||
@@ -1942,7 +1929,7 @@
|
||||
(or (state/get-editor-show-page-search?)
|
||||
(state/get-editor-show-page-search-hashtag?)
|
||||
(state/get-editor-show-block-search?)))
|
||||
(when-let [q (get-search-q)]
|
||||
(when (get-search-q)
|
||||
(let [value (gobj/get input "value")
|
||||
pos (:editor/last-saved-cursor @state/state)
|
||||
current-pos (cursor/pos input)
|
||||
@@ -1973,7 +1960,7 @@
|
||||
block (db/pull [:block/uuid block-id])
|
||||
value (:block/content block)
|
||||
new-value (string/replace value full_text new-full-text)]
|
||||
(save-block-aux! block new-value (:block/format block) {})))
|
||||
(save-block-aux! block new-value {})))
|
||||
|
||||
(defn- mark-last-input-time!
|
||||
[repo]
|
||||
@@ -2151,7 +2138,7 @@
|
||||
[tree exclude-properties {:keys [content-update-fn
|
||||
get-pos-fn
|
||||
page-block]
|
||||
:as opts}]
|
||||
:as _opts}]
|
||||
(let [repo (state/get-current-repo)
|
||||
page (or page-block
|
||||
(:block/page (db/entity (:db/id (state/get-edit-block)))))
|
||||
@@ -2280,7 +2267,7 @@
|
||||
(let [block (if (tree/satisfied-inode? last-block)
|
||||
(:data last-block)
|
||||
(:data (last (flatten last-block))))]
|
||||
(edit-block! block :max (:block/format block) (:block/uuid block))))))))
|
||||
(edit-block! block :max (:block/uuid block))))))))
|
||||
|
||||
(defn template-on-chosen-handler
|
||||
[element-id]
|
||||
@@ -2301,7 +2288,7 @@
|
||||
(db/refresh! repo {:key :block/change :data [(:data node)]})))
|
||||
|
||||
(defn- last-top-level-child?
|
||||
[{:keys [id config]} current-node]
|
||||
[{:keys [id]} current-node]
|
||||
(when id
|
||||
(when-let [entity (if (util/uuid-string? (str id))
|
||||
(db/entity [:block/uuid (uuid id)])
|
||||
@@ -2494,7 +2481,6 @@
|
||||
block (db/pull repo '[*] [:block/uuid new-uuid])]
|
||||
(edit-block! block
|
||||
[direction line-pos]
|
||||
format
|
||||
new-id))))))
|
||||
|
||||
(defn keydown-up-down-handler
|
||||
@@ -2525,18 +2511,18 @@
|
||||
pos (if up? :max 0)
|
||||
{:block/keys [format uuid] :as block} (state/get-edit-block)
|
||||
id (state/get-edit-input-id)
|
||||
repo (state/get-current-repo)]
|
||||
(let [f (if up? util/get-prev-block-non-collapsed util/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 [content (:block/content block)
|
||||
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 pos format id)))))))
|
||||
repo (state/get-current-repo)
|
||||
f (if up? util/get-prev-block-non-collapsed util/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 [content (:block/content block)
|
||||
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 pos id))))))
|
||||
|
||||
(defn keydown-arrow-handler
|
||||
[direction]
|
||||
@@ -2641,7 +2627,7 @@
|
||||
(= (medley/uuid page) block-id))))
|
||||
(do
|
||||
(util/stop e)
|
||||
(delete-block! repo e false))
|
||||
(delete-block! repo false))
|
||||
|
||||
(and (> current-pos 1)
|
||||
(= (util/nth-safe value (dec current-pos)) commands/slash))
|
||||
@@ -2731,7 +2717,7 @@
|
||||
|
||||
(defn keydown-not-matched-handler
|
||||
[format]
|
||||
(fn [e key-code]
|
||||
(fn [e _key-code]
|
||||
(let [input-id (state/get-edit-input-id)
|
||||
input (state/get-input)
|
||||
key (gobj/get e "key")
|
||||
@@ -2775,7 +2761,7 @@
|
||||
(commands/handle-step [:editor/search-block :reference])
|
||||
(reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
|
||||
:else
|
||||
nil))
|
||||
(reset! commands/*show-commands false)))
|
||||
|
||||
(or
|
||||
(surround-by? input "#" " ")
|
||||
@@ -2935,11 +2921,7 @@
|
||||
|
||||
(defn- paste-text
|
||||
[text e]
|
||||
(let [repo (state/get-current-repo)
|
||||
page (or (db/entity [:block/name (state/get-current-page)])
|
||||
(db/entity [:block/original-name (state/get-current-page)])
|
||||
(:block/page (db/entity (:db/id (state/get-edit-block)))))
|
||||
copied-blocks (state/get-copied-blocks)
|
||||
(let [copied-blocks (state/get-copied-blocks)
|
||||
copied-block-tree (:copy/block-tree copied-blocks)]
|
||||
(if (and
|
||||
(:copy/content copied-blocks)
|
||||
@@ -2990,7 +2972,7 @@
|
||||
(let [text (.getData (gobj/get e "clipboardData") "text")]
|
||||
(if-not (string/blank? text)
|
||||
(paste-text text e)
|
||||
(let [handled
|
||||
(let [_handled
|
||||
(let [clipboard-data (gobj/get e "clipboardData")
|
||||
files (.-files clipboard-data)]
|
||||
(when-let [file (first files)]
|
||||
@@ -3004,7 +2986,7 @@
|
||||
(clear-selection!))
|
||||
|
||||
(defn shortcut-copy-selection
|
||||
[e]
|
||||
[_e]
|
||||
(copy-selection-blocks))
|
||||
|
||||
(defn shortcut-cut-selection
|
||||
@@ -3110,7 +3092,6 @@
|
||||
left? (= direction :left)]
|
||||
(edit-block! block
|
||||
(if left? 0 :max)
|
||||
(:block/format block)
|
||||
block-id))))
|
||||
|
||||
(defn shortcut-left-right [direction]
|
||||
|
||||
Reference in New Issue
Block a user