Ver Fonte

Merge remote-tracking branch 'upstream/master' into whiteboards

Peng Xiao há 3 anos atrás
pai
commit
70db603097

+ 4 - 1
android/app/src/main/java/com/logseq/app/FolderPicker.java

@@ -20,6 +20,8 @@ import com.getcapacitor.annotation.CapacitorPlugin;
 import com.getcapacitor.PluginCall;
 import com.getcapacitor.PluginMethod;
 
+import java.io.File;
+
 
 @CapacitorPlugin(name = "FolderPicker")
 public class FolderPicker extends Plugin {
@@ -63,7 +65,8 @@ public class FolderPicker extends Plugin {
         if (path == null || path.isEmpty()) {
             call.reject("Cannot support this directory type: " + docUri);
         } else {
-            ret.put("path", "file://" + path);
+            Uri folderUri = Uri.fromFile(new File(path));
+            ret.put("path", folderUri.toString());
             call.resolve(ret);
         }
     }

+ 6 - 7
android/app/src/main/java/com/logseq/app/FsWatcher.java

@@ -58,7 +58,7 @@ public class FsWatcher extends Plugin {
 
             int mask = FileObserver.CLOSE_WRITE |
                     FileObserver.MOVE_SELF | FileObserver.MOVED_FROM | FileObserver.MOVED_TO |
-                    FileObserver.DELETE | FileObserver.DELETE_SELF;
+                    FileObserver.DELETE | FileObserver.DELETE_SELF | FileObserver.CREATE;
 
             if (observers != null) {
                 call.reject("already watching");
@@ -72,7 +72,7 @@ public class FsWatcher extends Plugin {
             if (files != null) {
                 for (File file : files) {
                     String filename = file.getName();
-                    if (file.isDirectory() && !filename.startsWith(".") && !filename.equals("bak") && !filename.equals("node_modules")) {
+                    if (file.isDirectory() && !filename.startsWith(".") && !filename.equals("bak") && !filename.equals("version-files") && !filename.equals("node_modules")) {
                         observers.add(new SingleFileObserver(file, mask));
                     }
                 }
@@ -90,7 +90,7 @@ public class FsWatcher extends Plugin {
 
     @PluginMethod()
     public void unwatch(PluginCall call) {
-        Log.i("FsWatcher", "unwatching...");
+        Log.i("FsWatcher", "unwatch all...");
 
         if (observers != null) {
             for (int i = 0; i < observers.size(); ++i)
@@ -129,11 +129,9 @@ public class FsWatcher extends Plugin {
     public void onObserverEvent(int event, String path) {
         JSObject obj = new JSObject();
         String content = null;
-        // FIXME: Current repo/path impl requires path to be a URL, dir to be a bare
-        // path.
         File f = new File(path);
         obj.put("path", Uri.fromFile(f));
-        obj.put("dir", "file://" + mPath);
+        obj.put("dir", Uri.fromFile(new File(mPath)));
 
         switch (event) {
             case FileObserver.CLOSE_WRITE:
@@ -223,7 +221,8 @@ public class FsWatcher extends Plugin {
         @Override
         public void onEvent(int event, String path) {
             if (path != null && !path.equals("graphs-txid.edn") && !path.equals("broken-config.edn")) {
-                Log.d("FsWatcher", "got path=" + path + " event=" + event);
+                Log.d("FsWatcher", "got path=" + mPath + "/" + path + " event=" + event);
+                // TODO: handle newly created directory
                 if (Pattern.matches("(?i)[^.].*?\\.(md|org|css|edn|js|markdown)$", path)) {
                     String fullPath = mPath + "/" + path;
                     if (event == FileObserver.MOVE_SELF || event == FileObserver.MOVED_FROM ||

+ 3 - 2
src/main/frontend/components/block.cljs

@@ -2477,7 +2477,8 @@
         *navigating-block (get state ::navigating-block)
         navigating-block (rum/react *navigating-block)
         navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
-        block (if navigated?
+        block (if (or (and custom-query? (empty? (:block/children block)))
+                      navigated?)
                 (let [block (db/pull [:block/uuid navigating-block])
                       blocks (db/get-paginated-blocks repo (:db/id block)
                                                       {:scoped-block-id (:db/id block)})
@@ -2606,7 +2607,7 @@
                     ::navigating-block (atom (:block/uuid block)))))
    :should-update (fn [old-state new-state]
                     (let [compare-keys [:block/uuid :block/content :block/parent :block/collapsed?
-                                        :block/properties :block/left :block/children :block/_refs]
+                                        :block/properties :block/left :block/children :block/_refs :block/bottom? :block/top?]
                           config-compare-keys [:show-cloze?]
                           b1 (second (:rum/args old-state))
                           b2 (second (:rum/args new-state))

+ 2 - 1
src/main/frontend/components/reference.cljs

@@ -200,7 +200,8 @@
           filters (when (seq filter-state)
                     (-> (group-by second filter-state)
                         (update-vals #(map first %))))
-          filtered-ref-blocks (block-handler/filter-blocks ref-blocks filters)
+          filtered-ref-blocks (->> (block-handler/filter-blocks ref-blocks filters)
+                                   (block-handler/get-filtered-ref-blocks-with-parents ref-blocks))
           total (count top-level-blocks)
           filtered-top-blocks (filter (fn [b] (top-level-blocks-ids (:db/id b))) filtered-ref-blocks)
           filter-n (count filtered-top-blocks)

+ 5 - 4
src/main/frontend/components/search.cljs

@@ -347,10 +347,11 @@
                             (let [page data]
                               (when (string? page)
                                 (when-let [page (db/pull [:block/name (util/page-name-sanity-lc page)])]
-                                  (state/sidebar-add-block!
-                                   (state/get-current-repo)
-                                   (:db/id page)
-                                   :page))))
+                                 (state/sidebar-add-block!
+                                  (state/get-current-repo)
+                                  (:db/id page)
+                                  :page))
+                                (state/close-modal!)))
 
                             nil))
        :item-render (fn [{:keys [type data]}]

+ 4 - 6
src/main/frontend/fs/capacitor_fs.cljs

@@ -275,12 +275,10 @@
     (readdir dir))
   (unlink! [this repo path _opts]
     (p/let [path (get-file-path nil path)
-            path (if (string/starts-with? path "file://")
-                   (string/replace-first path "file://" "")
-                   path)
-            repo-dir (config/get-local-dir repo)
-            recycle-dir (str repo-dir config/app-name "/.recycle") ;; logseq/.recycle
-            file-name (-> (string/replace path repo-dir "")
+            repo-url (config/get-local-dir repo)
+            recycle-dir (str repo-url config/app-name "/.recycle") ;; logseq/.recycle
+            ;; convert url to pure path
+            file-name (-> (string/replace path repo-url "")
                           (string/replace "/" "_")
                           (string/replace "\\" "_"))
             new-path (str recycle-dir "/" file-name)]

+ 19 - 4
src/main/frontend/handler/block.cljs

@@ -249,14 +249,17 @@
 
 (defn get-blocks-refed-pages
   [aliases ref-blocks]
-  (let [refs (->> (mapcat (fn [b] (conj (:block/path-refs b) (:block/page b))) ref-blocks)
-                  distinct
-                  (remove #(aliases (:db/id %))))]
+  (let [refs (->> (mapcat :block/refs ref-blocks)
+                  (remove #(aliases (:db/id %))))
+        pages (->> (map :block/page ref-blocks)
+                   (distinct)
+                   (remove #(aliases (:db/id %))))
+        all-refs (concat pages refs)]
     (keep (fn [ref]
             (when (:block/name ref)
               {:db/id (:db/id ref)
                :block/name (:block/name ref)
-               :block/original-name (:block/original-name ref)})) refs)))
+               :block/original-name (:block/original-name ref)})) all-refs)))
 
 (defn filter-blocks
   [ref-blocks filters]
@@ -276,3 +279,15 @@
         (filter (fn [block]
                   (let [ids (set (map :db/id (:block/path-refs block)))]
                     (set/subset? include-ids ids))))))))
+
+(defn get-filtered-ref-blocks-with-parents
+  [all-ref-blocks filtered-ref-blocks]
+  (when (seq filtered-ref-blocks)
+    (let [id->block (zipmap (map :db/id all-ref-blocks) all-ref-blocks)
+          get-parents (fn [block]
+                        (loop [block block
+                               result [block]]
+                          (if-let [parent (id->block (:db/id (:block/parent block)))]
+                            (recur parent (conj result parent))
+                            result)))]
+      (distinct (mapcat get-parents filtered-ref-blocks)))))

+ 0 - 1
src/main/frontend/modules/outliner/core.cljs

@@ -215,7 +215,6 @@
                          [:db/retract id :block/alias]
                          [:db/retract id :block/tags]])))]
       (swap! txs-state concat txs page-tx)
-      (util/pprint @txs-state)
       block-id))
 
   (-get-children [this]

+ 7 - 9
src/main/frontend/modules/shortcut/config.cljs

@@ -250,18 +250,16 @@
                                                 (route-handler/go-to-search! :global))}
 
    :go/electron-find-in-page       {:binding "mod+f"
-                                    :fn      #(when (util/electron?)
-                                                (search-handler/open-find-in-page!))}
-
+                                    :inactive (not (util/electron?))
+                                    :fn      #(search-handler/open-find-in-page!)}
+   
    :go/electron-jump-to-the-next {:binding ["enter" "mod+g"]
-                                    :fn      (fn [_state _e]
-                                               (when (util/electron?)
-                                                 (search-handler/loop-find-in-page! false)))}
+                                  :inactive (not (util/electron?))
+                                  :fn      #(search-handler/loop-find-in-page! false)}
 
    :go/electron-jump-to-the-previous {:binding ["shift+enter" "mod+shift+g"]
-                                             :fn      (fn [_state _e]
-                                                        (when (util/electron?)
-                                                          (search-handler/loop-find-in-page! true)))}
+                                      :inactive (not (util/electron?))
+                                      :fn      #(search-handler/loop-find-in-page! true)}
 
    :go/journals                    {:binding "g j"
                                     :fn      route-handler/go-to-journals!}

+ 6 - 6
templates/config.edn

@@ -141,12 +141,12 @@
  :default-queries
  {:journals
   [{:title "🔨 NOW"
-    :query [:find (pull ?h [*])
+    :query [:find (pull ?b [*])
             :in $ ?start ?today
             :where
-            [?h :block/marker ?marker]
+            [?b :block/marker ?marker]
             [(contains? #{"NOW" "DOING"} ?marker)]
-            [?h :block/page ?p]
+            [?b :block/page ?p]
             [?p :block/journal? true]
             [?p :block/journal-day ?d]
             [(>= ?d ?start)]
@@ -157,12 +157,12 @@
                                    (get h :block/priority "Z")) result))
     :collapsed? false}
    {:title "📅 NEXT"
-    :query [:find (pull ?h [*])
+    :query [:find (pull ?b [*])
             :in $ ?start ?next
             :where
-            [?h :block/marker ?marker]
+            [?b :block/marker ?marker]
             [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
-            [?h :block/ref-pages ?p]
+            [?b :block/page ?p]
             [?p :block/journal? true]
             [?p :block/journal-day ?d]
             [(> ?d ?start)]