From cb66a5ad7fe9402fb13803b8240aa869d32c1f2e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 20:26:40 +0800 Subject: [PATCH 01/15] fix: check and fix db schema --- deps/db/src/logseq/db/common/sqlite.cljs | 4 +--- deps/db/src/logseq/db/file_based/schema.cljs | 3 ++- src/main/frontend/worker/db/fix.cljs | 23 ++++++++++++++++++++ src/main/frontend/worker/db_worker.cljs | 2 ++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/main/frontend/worker/db/fix.cljs diff --git a/deps/db/src/logseq/db/common/sqlite.cljs b/deps/db/src/logseq/db/common/sqlite.cljs index 3c01af14da..34fc2afade 100644 --- a/deps/db/src/logseq/db/common/sqlite.cljs +++ b/deps/db/src/logseq/db/common/sqlite.cljs @@ -330,9 +330,7 @@ views all-files pages-datoms))] - (prn :debug "db-graph?" db-graph?) - (prn :debug "block/journal-day schema" (str (:block/journal-day (:schema db)))) - {:schema (assoc schema :block/journal-day {:db/index true}) + {:schema schema :initial-data data})) (defn restore-initial-data diff --git a/deps/db/src/logseq/db/file_based/schema.cljs b/deps/db/src/logseq/db/file_based/schema.cljs index b111d2565e..00e3beb83e 100644 --- a/deps/db/src/logseq/db/file_based/schema.cljs +++ b/deps/db/src/logseq/db/file_based/schema.cljs @@ -45,7 +45,8 @@ ;; for pages :block/alias {:db/valueType :db.type/ref - :db/cardinality :db.cardinality/many} + :db/cardinality :db.cardinality/many + :db/index true} ;; todo keywords, e.g. "TODO", "DOING", "DONE" :block/marker {} diff --git a/src/main/frontend/worker/db/fix.cljs b/src/main/frontend/worker/db/fix.cljs new file mode 100644 index 0000000000..b598ba7235 --- /dev/null +++ b/src/main/frontend/worker/db/fix.cljs @@ -0,0 +1,23 @@ +(ns frontend.worker.db.fix + "fix db" + (:require [datascript.core :as d] + [logseq.db.sqlite.util :as sqlite-util])) + +(defn check-and-fix-schema! + [repo conn] + (let [schema (sqlite-util/get-schema repo) + db-schema (:schema @conn) + diffs (->> (keep (fn [[k v]] + (let [schema-v (-> (get db-schema k) + (dissoc :db/ident)) + schema-v' (cond-> schema-v + (= (:db/cardinality schema-v) :db.cardinality/one) + (dissoc :db/cardinality) + (and (:db/index schema-v) + (nil? (:db/index v))) + (dissoc :db/index))] + (when-not (or (= v schema-v') (= k :db/ident)) + (assoc v :db/ident k)))) + schema))] + (when (seq diffs) + (d/transact! conn diffs)))) diff --git a/src/main/frontend/worker/db_worker.cljs b/src/main/frontend/worker/db_worker.cljs index 2051e6259f..1ed18b6361 100644 --- a/src/main/frontend/worker/db_worker.cljs +++ b/src/main/frontend/worker/db_worker.cljs @@ -13,6 +13,7 @@ [frontend.common.graph-view :as graph-view] [frontend.common.thread-api :as thread-api :refer [def-thread-api]] [frontend.worker.db-listener :as db-listener] + [frontend.worker.db.fix :as db-fix] [frontend.worker.db.migrate :as db-migrate] [frontend.worker.db.validate :as worker-db-validate] [frontend.worker.export :as worker-export] @@ -333,6 +334,7 @@ (search/create-tables-and-triggers! search-db) (let [schema (sqlite-util/get-schema repo) conn (sqlite-common-db/get-storage-conn storage schema) + _ (db-fix/check-and-fix-schema! repo conn) _ (when datoms (let [data (map (fn [datom] [:db/add (:e datom) (:a datom) (:v datom)]) datoms)] From 813d18402f5121199238d84305f5904b0f2bd292 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 20:38:29 +0800 Subject: [PATCH 02/15] fix: lint --- src/main/frontend/handler/events/ui.cljs | 41 ++++++++++++++++++- .../frontend/handler/file_based/events.cljs | 34 --------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/main/frontend/handler/events/ui.cljs b/src/main/frontend/handler/events/ui.cljs index 9089eb4c63..ab5f1055f6 100644 --- a/src/main/frontend/handler/events/ui.cljs +++ b/src/main/frontend/handler/events/ui.cljs @@ -1,7 +1,10 @@ (ns frontend.handler.events.ui "UI events" - (:require [frontend.components.block :as block] + (:require [clojure.core.async :as async] + [clojure.core.async.interop :refer [p->c]] + [frontend.components.block :as block] [frontend.components.cmdk.core :as cmdk] + [frontend.components.file-sync :as file-sync] [frontend.components.page :as component-page] [frontend.components.plugins :as plugin] [frontend.components.property.dialog :as property-dialog] @@ -20,6 +23,7 @@ [frontend.fs.capacitor-fs :as capacitor-fs] [frontend.fs.nfs :as nfs] [frontend.fs.sync :as sync] + [frontend.handler.db-based.rtc :as rtc-handler] [frontend.handler.editor :as editor-handler] [frontend.handler.events :as events] [frontend.handler.file-based.nfs :as nfs-handler] @@ -27,8 +31,11 @@ [frontend.handler.notification :as notification] [frontend.handler.page :as page-handler] [frontend.handler.plugin :as plugin-handler] + [frontend.handler.repo :as repo-handler] [frontend.handler.route :as route-handler] + [frontend.handler.user :as user-handler] [frontend.mobile.util :as mobile-util] + [frontend.modules.instrumentation.sentry :as sentry-event] [frontend.state :as state] [frontend.ui :as ui] [frontend.util :as util] @@ -352,3 +359,35 @@ (merge {:close-btn? false :center? true :close-backdrop? false} opts))) + +(defn- enable-beta-features! + [] + (when-not (false? (state/enable-sync?)) ; user turns it off + (file-sync-handler/set-sync-enabled! true))) + +;; TODO: separate rtc and file-based implementation +(defmethod events/handle :user/fetch-info-and-graphs [[_]] + (state/set-state! [:ui/loading? :login] false) + (async/go + (let [result (async/c (rtc-handler/c]] [clojure.set :as set] [clojure.string :as string] [frontend.components.diff :as diff] @@ -14,7 +13,6 @@ [frontend.fs :as fs] [frontend.fs.sync :as sync] [frontend.handler.common :as common-handler] - [frontend.handler.db-based.rtc :as rtc-handler] [frontend.handler.events :as events] [frontend.handler.file-based.file :as file-handler] [frontend.handler.file-based.nfs :as nfs-handler] @@ -28,7 +26,6 @@ [frontend.handler.user :as user-handler] [frontend.mobile.graph-picker :as graph-picker] [frontend.mobile.util :as mobile-util] - [frontend.modules.instrumentation.sentry :as sentry-event] [frontend.modules.shortcut.core :as st] [frontend.state :as state] [frontend.ui :as ui] @@ -164,37 +161,6 @@ opts)) {:center? true :close-btn? false :close-backdrop? false})) -(defn- enable-beta-features! - [] - (when-not (false? (state/enable-sync?)) ; user turns it off - (file-sync-handler/set-sync-enabled! true))) - -(defmethod events/handle :user/fetch-info-and-graphs [[_]] - (state/set-state! [:ui/loading? :login] false) - (async/go - (let [result (async/c (rtc-handler/ Date: Thu, 17 Apr 2025 20:28:23 +0800 Subject: [PATCH 03/15] =?UTF-8?q?enhance=20the=C2=A0/=C2=A0input=20toleran?= =?UTF-8?q?ce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/frontend/commands.cljs | 9 +++++++- src/main/frontend/components/editor.cljs | 4 +++- src/main/frontend/handler/editor.cljs | 25 +++++++++++++--------- src/test/frontend/handler/editor_test.cljs | 19 +++++++++++----- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index ee19b85269..b4c50a643c 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -299,6 +299,7 @@ (let [heading (str "Heading " level)] [heading (->heading level) heading (str "h-" level)])) (range 1 7))) +(defonce *latest-matched-command (atom "")) (defonce *matched-commands (atom nil)) (defonce *initial-commands (atom nil)) @@ -474,12 +475,18 @@ (defn init-commands! [get-page-ref-text] (let [commands (commands-map get-page-ref-text)] + (reset! *latest-matched-command "") (reset! *initial-commands commands) (reset! *matched-commands commands))) +(defn set-matched-commands! + [command matched-commands] + (reset! *latest-matched-command command) + (reset! *matched-commands matched-commands)) + (defn reinit-matched-commands! [] - (reset! *matched-commands @*initial-commands)) + (set-matched-commands! "" @*initial-commands)) (defn restore-state [] diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 98a04d3794..346f8e803d 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -38,6 +38,8 @@ [react-draggable] [rum.core :as rum])) +(defonce no-matched-coomands [["No matched commands" [[:editor/move-cursor-to-end]]]]) + (defn filter-commands [page? commands] (if page? @@ -56,7 +58,7 @@ _ (when (state/get-editor-action) (reset! *matched matched')) page? (db/page? (db/entity (:db/id (state/get-edit-block)))) - matched (filter-commands page? @*matched)] + matched (or (filter-commands page? @*matched) no-matched-coomands)] (ui/auto-complete matched {:get-group-name diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 6a39c91edb..90aaf3728b 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1773,23 +1773,25 @@ [property q] (search/property-value-search property q)) -(defn get-matched-commands +(defn get-last-command [input] (try (let [edit-content (or (gobj/get input "value") "") pos (cursor/pos input) last-slash-caret-pos (:pos (:pos (state/get-editor-action-data))) last-command (and last-slash-caret-pos (subs edit-content last-slash-caret-pos pos))] - (when (> pos 0) - (or - (and (= commands/command-trigger (util/nth-safe edit-content (dec pos))) - @commands/*initial-commands) - (and last-command - (commands/get-matched-commands last-command))))) + (when (> pos 0) last-command)) (catch :default e (js/console.error e) nil))) +(defn get-matched-commands + [command] + (condp = command + nil nil + "" @commands/*initial-commands + (commands/get-matched-commands command))) + (defn auto-complete? [] (or @*asset-uploading? @@ -3206,10 +3208,13 @@ (and (= :commands (state/get-editor-action)) (not= k commands/command-trigger)) (if (= commands/command-trigger (second (re-find #"(\S+)\s+$" value))) (state/clear-editor-action!) - (let [matched-commands (get-matched-commands input)] + (let [command (get-last-command input) + matched-commands (get-matched-commands command)] (if (seq matched-commands) - (reset! commands/*matched-commands matched-commands) - (state/clear-editor-action!)))) + (commands/set-matched-commands! command matched-commands) + (if (> (- (count command) (count @commands/*latest-matched-command)) 1) + (state/clear-editor-action!) + (reset! commands/*matched-commands nil))))) :else (default-case-for-keyup-handler input current-pos k code is-processed?)) diff --git a/src/test/frontend/handler/editor_test.cljs b/src/test/frontend/handler/editor_test.cljs index 2dfa6841d9..f330141b51 100644 --- a/src/test/frontend/handler/editor_test.cljs +++ b/src/test/frontend/handler/editor_test.cljs @@ -82,8 +82,10 @@ (state/set-editor-action! action) ;; Default cursor pos to end of line (let [pos (or cursor-pos (count value)) - input #js {:value value}] - (with-redefs [editor/get-matched-commands (constantly commands) + input #js {:value value} + command (subs value 1)] + (with-redefs [editor/get-last-command (constantly command) + editor/get-matched-commands (constantly commands) ;; Ignore as none of its behaviors are tested editor/default-case-for-keyup-handler (constantly nil) cursor/pos (constantly pos)] @@ -93,11 +95,12 @@ (deftest keyup-handler-test (testing "Command autocompletion" - (keyup-handler {:value "/b" + ;; default last matching command is "" + (keyup-handler {:value "/z" :action :commands - :commands [:fake-command]}) + :commands []}) (is (= :commands (state/get-editor-action)) - "Completion stays open if there is a matching command") + "Completion stays open if no matches but differs by 1 character from last matching command") (keyup-handler {:value "/zz" :action :commands @@ -105,6 +108,12 @@ (is (= nil (state/get-editor-action)) "Completion closed if there no matching commands") + (keyup-handler {:value "/b" + :action :commands + :commands [:fake-command]}) + (is (= :commands (state/get-editor-action)) + "Completion stays open if there is a matching command") + (keyup-handler {:value "/ " :action :commands}) (is (= nil (state/get-editor-action)) "Completion closed after a space follows /") From b30f679eefef0d6e0f5806fd4d7a0307ab5cc260 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 20:48:39 +0800 Subject: [PATCH 04/15] fix: lint --- src/main/frontend/handler/events/ui.cljs | 9 +++++++++ src/main/frontend/handler/file_based/events.cljs | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/frontend/handler/events/ui.cljs b/src/main/frontend/handler/events/ui.cljs index ab5f1055f6..4e322209af 100644 --- a/src/main/frontend/handler/events/ui.cljs +++ b/src/main/frontend/handler/events/ui.cljs @@ -391,3 +391,12 @@ (util/uuid-string? (second (:sync-meta %)))) repos) (sync/ Date: Thu, 17 Apr 2025 21:08:03 +0800 Subject: [PATCH 05/15] fix: can't set status in page reference --- src/main/frontend/components/block.cljs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index ce750bf85f..d90e63c15d 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1068,7 +1068,7 @@ (contains? config/video-formats asset-type)))) (declare block-positioned-properties) -(rum/defc page-reference < rum/reactive +(rum/defc page-reference < rum/reactive db-mixins/query "Component for page reference" [html-export? uuid-or-title* {:keys [nested-link? show-brackets? id] :as config} label] (when uuid-or-title* @@ -1077,7 +1077,8 @@ uuid-or-title*) show-brackets? (if (some? show-brackets?) show-brackets? (state/show-brackets?)) contents-page? (= "contents" (string/lower-case (str id))) - block (db/get-page uuid-or-title) + block* (db/get-page uuid-or-title) + block (or (some-> (:db/id block*) db/sub-block) block*) config' (assoc config :label (mldoc/plain->text label) :contents-page? contents-page? From 424dfce32ce88df0afdc49ad9808d2c4f3bf4018 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 17 Apr 2025 09:39:20 -0400 Subject: [PATCH 06/15] fix: backspace on block with property deletes prev children Fixes https://github.com/logseq/db-test/issues/249 --- src/main/frontend/handler/editor.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 6a39c91edb..6d629b9383 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -818,7 +818,7 @@ concat-prev-block? (let [children (:block/_parent (db/entity (:db/id block))) db-based? (config/db-based-graph? repo) - prev-block-is-not-parent? (not= (:block/uuid (:block/parent block)) (:block/uuid prev-block)) + prev-block-is-not-parent? (empty? (:block/_parent prev-block)) delete-prev-block? (and db-based? prev-block-is-not-parent? (empty? (:block/tags block)) From 5bd127b10161bbb9af77080db2cfca50f5475ba9 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 21:41:28 +0800 Subject: [PATCH 07/15] fix: fuzzy search on commands returns wrong result --- src/main/frontend/commands.cljs | 27 +++++++++++------------- src/main/frontend/components/editor.cljs | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index ee19b85269..eda82796bb 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -241,19 +241,16 @@ (if db-based? (db-based-statuses) (file-based-statuses)) - (mapv (fn [m] - (let [command (if db-based? - [:div.flex.flex-row.items-center.gap-2 m [:div.text-xs.opacity-50 "Status"]] - m) - icon (if db-based? - (case m + (mapv (fn [command] + (let [icon (if db-based? + (case command "Canceled" "Cancelled" "Doing" "InProgress50" - m) + command) "square-asterisk")] - [command (->marker m) (str "Set status to " m) icon]))))] + [command (->marker command) (str "Set status to " command) icon]))))] (when (seq result) - (map (fn [v] (conj v "TASK")) result)))) + (map (fn [v] (conj v "TASK STATUS")) result)))) (defn file-based-priorities [] @@ -273,17 +270,17 @@ (db-based-priorities) (file-based-priorities)) (mapv (fn [item] - (let [command (if db-based? - [:div.flex.flex-row.items-center.gap-2 item [:div.text-xs.opacity-50 "Priority"]] - item)] - [command (->priority item) (str "Set priority to " item) + (let [command item] + [command + (->priority item) + (str "Set priority to " item) (if db-based? (str "priorityLvl" item) (str "circle-letter-" (util/safe-lower-case item)))]))) (with-no-priority) (vec))] (when (seq result) - (map (fn [v] (conj v "PRIORITY")) result)))) + (map (fn [v] (into v ["PRIORITY"])) result)))) ;; Credits to roamresearch.com @@ -297,7 +294,7 @@ [] (mapv (fn [level] (let [heading (str "Heading " level)] - [heading (->heading level) heading (str "h-" level)])) (range 1 7))) + [heading (->heading level) heading (str "h-" level) "Heading"])) (range 1 7))) (defonce *matched-commands (atom nil)) (defonce *initial-commands (atom nil)) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 98a04d3794..bc9eaac8df 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -45,7 +45,7 @@ (or (= "Add new property" (first item)) (when (= (count item) 5) - (contains? #{"TASK" "PRIORITY"} (last item))))) commands) + (contains? #{"TASK STATUS" "PRIORITY"} (last item))))) commands) commands)) (rum/defcs commands < rum/reactive From 1d4c6a100f249b99ba9132533a12c4eb97b11d7e Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 21:53:25 +0800 Subject: [PATCH 08/15] enhance: hide group when user already input some command text --- src/main/frontend/components/editor.cljs | 94 ++++++++++++------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index bc9eaac8df..9ce0cd5e26 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -56,57 +56,59 @@ _ (when (state/get-editor-action) (reset! *matched matched')) page? (db/page? (db/entity (:db/id (state/get-edit-block)))) - matched (filter-commands page? @*matched)] + matched (filter-commands page? @*matched) + filtered? (not= matched @commands/*initial-commands)] (ui/auto-complete matched - {:get-group-name - (fn [item] - (when (= (count item) 5) (last item))) + (cond-> + {:item-render + (fn [item] + (let [command-name (first item) + command-doc (get item 2) + plugin-id (get-in item [1 1 1 :pid]) + doc (when (state/show-command-doc?) command-doc) + options (some-> item (get 3)) + icon-name (some-> (if (map? options) (:icon options) options) (name)) + command-name (if icon-name + [:span.flex.items-center.gap-1 + (shui/tabler-icon icon-name) + [:strong.font-normal command-name]] + command-name)] + (cond + (or plugin-id (vector? doc)) + [:div.has-help + {:title plugin-id} + command-name + (when doc (ui/tooltip [:small (svg/help-circle)] doc))] - :item-render - (fn [item] - (let [command-name (first item) - command-doc (get item 2) - plugin-id (get-in item [1 1 1 :pid]) - doc (when (state/show-command-doc?) command-doc) - options (some-> item (get 3)) - icon-name (some-> (if (map? options) (:icon options) options) (name)) - command-name (if icon-name - [:span.flex.items-center.gap-1 - (shui/tabler-icon icon-name) - [:strong.font-normal command-name]] - command-name)] - (cond - (or plugin-id (vector? doc)) - [:div.has-help - {:title plugin-id} - command-name - (when doc (ui/tooltip [:small (svg/help-circle)] doc))] + (string? doc) + [:div {:title doc} + command-name] - (string? doc) - [:div {:title doc} - command-name] + :else + [:div command-name]))) - :else - [:div command-name]))) - - :on-chosen - (fn [chosen-item] - (let [command (first chosen-item)] - (reset! commands/*current-command command) - (let [command-steps (get (into {} matched) command) - restore-slash? (or - (contains? #{"Today" "Yesterday" "Tomorrow" "Current time"} command) - (and - (not (fn? command-steps)) - (not (contains? (set (map first command-steps)) :editor/input)) - (not (contains? #{"Date picker" "Template" "Deadline" "Scheduled" "Upload an image"} command))))] - (editor-handler/insert-command! id command-steps - format - {:restore? restore-slash? - :command command})))) - :class - "cp__commands-slash"}))) + :on-chosen + (fn [chosen-item] + (let [command (first chosen-item)] + (reset! commands/*current-command command) + (let [command-steps (get (into {} matched) command) + restore-slash? (or + (contains? #{"Today" "Yesterday" "Tomorrow" "Current time"} command) + (and + (not (fn? command-steps)) + (not (contains? (set (map first command-steps)) :editor/input)) + (not (contains? #{"Date picker" "Template" "Deadline" "Scheduled" "Upload an image"} command))))] + (editor-handler/insert-command! id command-steps + format + {:restore? restore-slash? + :command command})))) + :class + "cp__commands-slash"} + (not filtered?) + (assoc :get-group-name + (fn [item] + (when (= (count item) 5) (last item)))))))) (defn- page-on-chosen-handler [embed? input id q pos format] From 031ab92709c52c67a80aa9dd313ce9dcc847ec29 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 21:08:03 +0800 Subject: [PATCH 09/15] fix: can't set status in page reference --- src/main/frontend/components/block.cljs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index ce750bf85f..d90e63c15d 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1068,7 +1068,7 @@ (contains? config/video-formats asset-type)))) (declare block-positioned-properties) -(rum/defc page-reference < rum/reactive +(rum/defc page-reference < rum/reactive db-mixins/query "Component for page reference" [html-export? uuid-or-title* {:keys [nested-link? show-brackets? id] :as config} label] (when uuid-or-title* @@ -1077,7 +1077,8 @@ uuid-or-title*) show-brackets? (if (some? show-brackets?) show-brackets? (state/show-brackets?)) contents-page? (= "contents" (string/lower-case (str id))) - block (db/get-page uuid-or-title) + block* (db/get-page uuid-or-title) + block (or (some-> (:db/id block*) db/sub-block) block*) config' (assoc config :label (mldoc/plain->text label) :contents-page? contents-page? From 76c60b59c96bf9a7ee30ccfc80bfdcbd003514c5 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 17 Apr 2025 09:39:20 -0400 Subject: [PATCH 10/15] fix: backspace on block with property deletes prev children Fixes https://github.com/logseq/db-test/issues/249 --- src/main/frontend/handler/editor.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 90aaf3728b..b1542c1bf2 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -818,7 +818,7 @@ concat-prev-block? (let [children (:block/_parent (db/entity (:db/id block))) db-based? (config/db-based-graph? repo) - prev-block-is-not-parent? (not= (:block/uuid (:block/parent block)) (:block/uuid prev-block)) + prev-block-is-not-parent? (empty? (:block/_parent prev-block)) delete-prev-block? (and db-based? prev-block-is-not-parent? (empty? (:block/tags block)) From 9a9469891768e0db82e46b66e0acbf3a4013c914 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 21:41:28 +0800 Subject: [PATCH 11/15] fix: fuzzy search on commands returns wrong result --- src/main/frontend/commands.cljs | 27 +++++++++++------------- src/main/frontend/components/editor.cljs | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index b4c50a643c..b528a73152 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -241,19 +241,16 @@ (if db-based? (db-based-statuses) (file-based-statuses)) - (mapv (fn [m] - (let [command (if db-based? - [:div.flex.flex-row.items-center.gap-2 m [:div.text-xs.opacity-50 "Status"]] - m) - icon (if db-based? - (case m + (mapv (fn [command] + (let [icon (if db-based? + (case command "Canceled" "Cancelled" "Doing" "InProgress50" - m) + command) "square-asterisk")] - [command (->marker m) (str "Set status to " m) icon]))))] + [command (->marker command) (str "Set status to " command) icon]))))] (when (seq result) - (map (fn [v] (conj v "TASK")) result)))) + (map (fn [v] (conj v "TASK STATUS")) result)))) (defn file-based-priorities [] @@ -273,17 +270,17 @@ (db-based-priorities) (file-based-priorities)) (mapv (fn [item] - (let [command (if db-based? - [:div.flex.flex-row.items-center.gap-2 item [:div.text-xs.opacity-50 "Priority"]] - item)] - [command (->priority item) (str "Set priority to " item) + (let [command item] + [command + (->priority item) + (str "Set priority to " item) (if db-based? (str "priorityLvl" item) (str "circle-letter-" (util/safe-lower-case item)))]))) (with-no-priority) (vec))] (when (seq result) - (map (fn [v] (conj v "PRIORITY")) result)))) + (map (fn [v] (into v ["PRIORITY"])) result)))) ;; Credits to roamresearch.com @@ -297,7 +294,7 @@ [] (mapv (fn [level] (let [heading (str "Heading " level)] - [heading (->heading level) heading (str "h-" level)])) (range 1 7))) + [heading (->heading level) heading (str "h-" level) "Heading"])) (range 1 7))) (defonce *latest-matched-command (atom "")) (defonce *matched-commands (atom nil)) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 346f8e803d..c61b1dbde7 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -47,7 +47,7 @@ (or (= "Add new property" (first item)) (when (= (count item) 5) - (contains? #{"TASK" "PRIORITY"} (last item))))) commands) + (contains? #{"TASK STATUS" "PRIORITY"} (last item))))) commands) commands)) (rum/defcs commands < rum/reactive From 2f5625818c7807cbd4b87a922e80f61a3bc55363 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 17 Apr 2025 21:53:25 +0800 Subject: [PATCH 12/15] resolve conflicts --- src/main/frontend/components/editor.cljs | 94 ++++++++++++------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index c61b1dbde7..c9007757cc 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -58,57 +58,59 @@ _ (when (state/get-editor-action) (reset! *matched matched')) page? (db/page? (db/entity (:db/id (state/get-edit-block)))) - matched (or (filter-commands page? @*matched) no-matched-coomands)] + matched (or (filter-commands page? @*matched) no-matched-coomands) + filtered? (not= matched @commands/*initial-commands)] (ui/auto-complete matched - {:get-group-name - (fn [item] - (when (= (count item) 5) (last item))) + (cond-> + {:item-render + (fn [item] + (let [command-name (first item) + command-doc (get item 2) + plugin-id (get-in item [1 1 1 :pid]) + doc (when (state/show-command-doc?) command-doc) + options (some-> item (get 3)) + icon-name (some-> (if (map? options) (:icon options) options) (name)) + command-name (if icon-name + [:span.flex.items-center.gap-1 + (shui/tabler-icon icon-name) + [:strong.font-normal command-name]] + command-name)] + (cond + (or plugin-id (vector? doc)) + [:div.has-help + {:title plugin-id} + command-name + (when doc (ui/tooltip [:small (svg/help-circle)] doc))] - :item-render - (fn [item] - (let [command-name (first item) - command-doc (get item 2) - plugin-id (get-in item [1 1 1 :pid]) - doc (when (state/show-command-doc?) command-doc) - options (some-> item (get 3)) - icon-name (some-> (if (map? options) (:icon options) options) (name)) - command-name (if icon-name - [:span.flex.items-center.gap-1 - (shui/tabler-icon icon-name) - [:strong.font-normal command-name]] - command-name)] - (cond - (or plugin-id (vector? doc)) - [:div.has-help - {:title plugin-id} - command-name - (when doc (ui/tooltip [:small (svg/help-circle)] doc))] + (string? doc) + [:div {:title doc} + command-name] - (string? doc) - [:div {:title doc} - command-name] + :else + [:div command-name]))) - :else - [:div command-name]))) - - :on-chosen - (fn [chosen-item] - (let [command (first chosen-item)] - (reset! commands/*current-command command) - (let [command-steps (get (into {} matched) command) - restore-slash? (or - (contains? #{"Today" "Yesterday" "Tomorrow" "Current time"} command) - (and - (not (fn? command-steps)) - (not (contains? (set (map first command-steps)) :editor/input)) - (not (contains? #{"Date picker" "Template" "Deadline" "Scheduled" "Upload an image"} command))))] - (editor-handler/insert-command! id command-steps - format - {:restore? restore-slash? - :command command})))) - :class - "cp__commands-slash"}))) + :on-chosen + (fn [chosen-item] + (let [command (first chosen-item)] + (reset! commands/*current-command command) + (let [command-steps (get (into {} matched) command) + restore-slash? (or + (contains? #{"Today" "Yesterday" "Tomorrow" "Current time"} command) + (and + (not (fn? command-steps)) + (not (contains? (set (map first command-steps)) :editor/input)) + (not (contains? #{"Date picker" "Template" "Deadline" "Scheduled" "Upload an image"} command))))] + (editor-handler/insert-command! id command-steps + format + {:restore? restore-slash? + :command command})))) + :class + "cp__commands-slash"} + (not filtered?) + (assoc :get-group-name + (fn [item] + (when (= (count item) 5) (last item)))))))) (defn- page-on-chosen-handler [embed? input id q pos format] From 3a6888d48a4fa89b6532ffc25fec71e13e4aefad Mon Sep 17 00:00:00 2001 From: Mega Yu Date: Thu, 17 Apr 2025 23:00:22 +0800 Subject: [PATCH 13/15] command input tolerance threshold set to 2 --- src/main/frontend/components/editor.cljs | 4 ++-- src/main/frontend/handler/editor.cljs | 2 +- src/test/frontend/handler/editor_test.cljs | 12 +++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index c9007757cc..84a59e272a 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -38,7 +38,7 @@ [react-draggable] [rum.core :as rum])) -(defonce no-matched-coomands [["No matched commands" [[:editor/move-cursor-to-end]]]]) +(defonce no-matched-commands [["No matched commands" [[:editor/move-cursor-to-end]]]]) (defn filter-commands [page? commands] @@ -58,7 +58,7 @@ _ (when (state/get-editor-action) (reset! *matched matched')) page? (db/page? (db/entity (:db/id (state/get-edit-block)))) - matched (or (filter-commands page? @*matched) no-matched-coomands) + matched (or (filter-commands page? @*matched) no-matched-commands) filtered? (not= matched @commands/*initial-commands)] (ui/auto-complete matched diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index b1542c1bf2..8f17022f35 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -3212,7 +3212,7 @@ matched-commands (get-matched-commands command)] (if (seq matched-commands) (commands/set-matched-commands! command matched-commands) - (if (> (- (count command) (count @commands/*latest-matched-command)) 1) + (if (> (- (count command) (count @commands/*latest-matched-command)) 2) (state/clear-editor-action!) (reset! commands/*matched-commands nil))))) diff --git a/src/test/frontend/handler/editor_test.cljs b/src/test/frontend/handler/editor_test.cljs index f330141b51..885b8b71de 100644 --- a/src/test/frontend/handler/editor_test.cljs +++ b/src/test/frontend/handler/editor_test.cljs @@ -93,20 +93,26 @@ #js {:key (subs value (dec (count value)))} nil)))) -(deftest keyup-handler-test +(deftest ^:focus keyup-handler-test (testing "Command autocompletion" ;; default last matching command is "" (keyup-handler {:value "/z" :action :commands :commands []}) (is (= :commands (state/get-editor-action)) - "Completion stays open if no matches but differs by 1 character from last matching command") + "Completion stays open if no matches but differs from last success by <= 2 chars") (keyup-handler {:value "/zz" :action :commands :commands []}) + (is (= :commands (state/get-editor-action)) + "Completion stays open if no matches but differs from last success by <= 2 chars") + + (keyup-handler {:value "/zzz" + :action :commands + :commands []}) (is (= nil (state/get-editor-action)) - "Completion closed if there no matching commands") + "Completion closed if no matches and > 2 chars form last success") (keyup-handler {:value "/b" :action :commands From c56f3312dfe5eea9044ae0adc50eeb5eddc85537 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 17 Apr 2025 13:43:18 -0400 Subject: [PATCH 14/15] fix: resizing image breaks validity of :url blocks db graphs should storing this in properties, not text. Fixes https://github.com/logseq/db-test/issues/241 --- src/main/frontend/handler/editor.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 6d629b9383..c75b490f57 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1929,9 +1929,9 @@ (defn resize-image! [config block-id metadata full_text size] (let [asset (:asset-block config)] - (if (and asset (config/db-based-graph?)) + (if (config/db-based-graph?) (property-handler/set-block-property! (state/get-current-repo) - (:db/id asset) + (if asset (:db/id asset) block-id) :logseq.property.asset/resize-metadata size) (let [new-meta (merge metadata size) From 548971bdf4324725e0abfd7bfa02d8d70a0b39e8 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 17 Apr 2025 14:28:05 -0400 Subject: [PATCH 15/15] chore: remove test :focus --- src/test/frontend/handler/editor_test.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/frontend/handler/editor_test.cljs b/src/test/frontend/handler/editor_test.cljs index 885b8b71de..0b2de3bb05 100644 --- a/src/test/frontend/handler/editor_test.cljs +++ b/src/test/frontend/handler/editor_test.cljs @@ -93,7 +93,7 @@ #js {:key (subs value (dec (count value)))} nil)))) -(deftest ^:focus keyup-handler-test +(deftest keyup-handler-test (testing "Command autocompletion" ;; default last matching command is "" (keyup-handler {:value "/z"