فهرست منبع

add entry history for ez jumping

biblius 2 هفته پیش
والد
کامیت
9bf7f52ec0

+ 1 - 3
package.json

@@ -22,7 +22,6 @@
     "@tailwindcss/vite": "^4.1.17",
     "@tauri-apps/api": "^2",
     "@tauri-apps/plugin-fs": "^2.4.5",
-    "@tauri-apps/plugin-global-shortcut": "^2.3.1",
     "@tauri-apps/plugin-log": "^2.7.1",
     "@tauri-apps/plugin-opener": "^2",
     "@tauri-apps/plugin-store": "^2.4.1",
@@ -32,8 +31,7 @@
     "mode-watcher": "^1.1.0",
     "svelte-highlight": "^7.9.0",
     "tailwind-merge": "^3.4.0",
-    "tailwindcss": "^4.1.17",
-    "thememirror": "^2.0.1"
+    "tailwindcss": "^4.1.17"
   },
   "devDependencies": {
     "@internationalized/date": "^3.10.0",

+ 0 - 67
src-tauri/Cargo.lock

@@ -1474,16 +1474,6 @@ dependencies = [
  "version_check",
 ]
 
-[[package]]
-name = "gethostname"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
-dependencies = [
- "rustix",
- "windows-link 0.2.1",
-]
-
 [[package]]
 name = "getrandom"
 version = "0.1.16"
@@ -1603,24 +1593,6 @@ version = "0.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
 
-[[package]]
-name = "global-hotkey"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9247516746aa8e53411a0db9b62b0e24efbcf6a76e0ba73e5a91b512ddabed7"
-dependencies = [
- "crossbeam-channel",
- "keyboard-types",
- "objc2 0.6.3",
- "objc2-app-kit",
- "once_cell",
- "serde",
- "thiserror 2.0.17",
- "windows-sys 0.59.0",
- "x11rb",
- "xkeysym",
-]
-
 [[package]]
 name = "gobject-sys"
 version = "0.18.0"
@@ -3694,7 +3666,6 @@ dependencies = [
  "tauri",
  "tauri-build",
  "tauri-plugin-fs",
- "tauri-plugin-global-shortcut",
  "tauri-plugin-log",
  "tauri-plugin-opener",
  "tauri-plugin-store",
@@ -4822,21 +4793,6 @@ dependencies = [
  "url",
 ]
 
-[[package]]
-name = "tauri-plugin-global-shortcut"
-version = "2.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "424af23c7e88d05e4a1a6fc2c7be077912f8c76bd7900fd50aa2b7cbf5a2c405"
-dependencies = [
- "global-hotkey",
- "log",
- "serde",
- "serde_json",
- "tauri",
- "tauri-plugin",
- "thiserror 2.0.17",
-]
-
 [[package]]
 name = "tauri-plugin-log"
 version = "2.7.1"
@@ -6441,29 +6397,6 @@ dependencies = [
  "pkg-config",
 ]
 
-[[package]]
-name = "x11rb"
-version = "0.13.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414"
-dependencies = [
- "gethostname",
- "rustix",
- "x11rb-protocol",
-]
-
-[[package]]
-name = "x11rb-protocol"
-version = "0.13.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
-
-[[package]]
-name = "xkeysym"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
-
 [[package]]
 name = "yoke"
 version = "0.8.1"

+ 0 - 3
src-tauri/Cargo.toml

@@ -60,6 +60,3 @@ opt-level = "s"   # Prioritizes small binary size. Use `3` if you prefer speed.
 panic = "abort"   # Higher performance by disabling panic handlers.
 strip = true      # Ensures debug symbols are removed.
 # rustflags = ["-Z", "threads=8"]
-
-[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
-tauri-plugin-global-shortcut = "2"

+ 0 - 1
src-tauri/capabilities/default.json

@@ -10,4 +10,3 @@
     "store:default"
   ]
 }
-

+ 5 - 12
src-tauri/capabilities/desktop.json

@@ -1,14 +1,7 @@
 {
   "identifier": "desktop-capability",
-  "platforms": [
-    "macOS",
-    "windows",
-    "linux"
-  ],
-  "windows": [
-    "main"
-  ],
-  "permissions": [
-    "global-shortcut:default"
-  ]
-}
+  "platforms": ["macOS", "windows", "linux"],
+  "windows": ["main"],
+  "permissions": []
+}
+

+ 0 - 1
src-tauri/src/lib.rs

@@ -18,7 +18,6 @@ mod workspace;
 pub fn run() {
     tauri::Builder::default()
         .plugin(tauri_plugin_fs::init())
-        // .plugin(tauri_plugin_global_shortcut::Builder::new().build())
         .plugin(tauri_plugin_store::Builder::new().build())
         .plugin(
             tauri_plugin_log::Builder::new()

+ 15 - 3
src/lib/components/WorkspaceEntry.svelte

@@ -270,7 +270,11 @@
             <Tabs.Content value="params" class="space-y-4">
               {#if _state.entry?.path?.length > 0}
                 <div>
-                  <h3 class="mb-2 text-sm font-medium">Path</h3>
+                  <h3
+                    class="mb-2 pointer-events-none text-xs font-medium border-b border-secondary text-muted-foreground"
+                  >
+                    Path
+                  </h3>
                   <div class="grid grid-cols-2 gap-2 text-sm">
                     {#each _state.entry.path as param}
                       <Input
@@ -302,7 +306,11 @@
 
               {#if _state.entry?.query?.length > 0}
                 <div>
-                  <h3 class="mb-2 text-sm font-medium">Query</h3>
+                  <h3
+                    class="mb-2 pointer-events-none text-xs font-medium border-b border-secondary text-muted-foreground"
+                  >
+                    Query
+                  </h3>
                   <div
                     class="grid grid-cols-[2%_1fr_1fr_2%] items-center justify-center gap-2 text-sm"
                   >
@@ -353,7 +361,11 @@
               <!-- ================= BODY ================= -->
 
               <div class="space-y-4">
-                <h3 class="mb-2 text-sm font-medium">Body</h3>
+                <h3
+                  class="mb-2 pointer-events-none text-xs font-medium border-b border-secondary text-muted-foreground"
+                >
+                  Body
+                </h3>
                 <Tabs.Root value={_state.entry.body === null ? "none" : "json"}>
                   <Tabs.List>
                     <Tabs.Trigger value="none" onclick={deleteBody}

+ 73 - 2
src/lib/state.svelte.ts

@@ -67,6 +67,16 @@ export type WorkspaceState = {
    * Maps request IDs to their latest response.
    */
   responses: Record<number, HttpResponse>;
+
+  /**
+   * Holds entry selection history.
+   */
+  entryHistory: number[];
+
+  /**
+   * Holds the currently selected entry index.
+   */
+  entryIndex: number;
 };
 
 export const state: WorkspaceState = $state({
@@ -80,6 +90,8 @@ export const state: WorkspaceState = $state({
   auth: [],
   pendingRequests: [],
   responses: {},
+  entryHistory: [],
+  entryIndex: 0,
 });
 
 const index = (entry: WorkspaceEntry) => {
@@ -97,6 +109,11 @@ const index = (entry: WorkspaceEntry) => {
   }
 };
 
+const reIndex = (entry: WorkspaceEntry) => {
+  console.log("re-indexing", entry);
+  state.indexes[entry.id] = entry;
+};
+
 function reset() {
   state.children = {};
   state.indexes = {};
@@ -107,6 +124,8 @@ function reset() {
   state.auth = [];
   state.pendingRequests = [];
   state.responses = {};
+  state.entryHistory = [];
+  state.entryIndex = 0;
 }
 
 /**
@@ -168,7 +187,56 @@ export function selectWorkspace(ws: Workspace) {
   state.workspace = ws;
 }
 
+export async function selectPreviousEntry() {
+  if (state.entryHistory.length === 0) {
+    return;
+  }
+
+  if (state.entryIndex === 0) {
+    return;
+  }
+
+  state.entryIndex -= 1;
+  state.entry = state.indexes[state.entryHistory[state.entryIndex]];
+  console.log($state.snapshot(state.entryIndex));
+  console.log($state.snapshot(state.entryHistory));
+}
+
+export async function selectNextEntry() {
+  if (state.entryHistory.length === 0) {
+    return;
+  }
+
+  if (state.entryIndex === state.entryHistory.length - 1) {
+    return;
+  }
+
+  state.entryIndex += 1;
+  state.entry = state.indexes[state.entryHistory[state.entryIndex]];
+  console.log($state.snapshot(state.entryIndex));
+  console.log($state.snapshot(state.entryHistory));
+}
+
+function pushEntry(id: number) {
+  if (state.entryIndex < state.entryHistory.length - 1) {
+    state.entryHistory.splice(state.entryIndex + 1);
+  }
+
+  if (state.entryHistory[state.entryHistory.length - 1] !== id) {
+    state.entryHistory.push(id);
+  }
+
+  state.entryIndex = state.entryHistory.length - 1;
+
+  console.log($state.snapshot(state.entryIndex));
+  console.log($state.snapshot(state.entryHistory));
+}
+
 export async function selectEntry(id: number) {
+  if (state.entry?.id === id) {
+    return;
+  }
+
   const entry = await invoke<WorkspaceEntryResponse>("get_workspace_entry", {
     entryId: id,
   });
@@ -192,13 +260,16 @@ export async function selectEntry(id: number) {
     }
   }
 
+  reIndex(state.entry);
+  pushEntry(id);
+
   console.log("selected entry:", $state.snapshot(state.entry));
 
   if (state.entry.parent_id != null) {
     let parent = state.indexes[state.entry.parent_id];
     while (parent) {
       parent.open = true;
-      if (parent.parent_id === null) {
+      if (parent.parent_id == null) {
         break;
       }
       parent = state.indexes[parent.parent_id];
@@ -406,7 +477,7 @@ export async function updateEntryName(name: string) {
     return;
   }
 
-  console.debug(state.entry.id, "updating entry name to", name);
+  console.debug("entry name update", state.entry.id, name);
 
   await invoke("update_workspace_entry", {
     entryId: state.entry.id,

+ 17 - 1
src/routes/+page.svelte

@@ -5,7 +5,11 @@
   import { Button } from "$lib/components/ui/button";
   import { SunIcon, MoonIcon, Lock } from "@lucide/svelte";
   import WorkspaceEntry from "$lib/components/WorkspaceEntry.svelte";
-  import { state as _state } from "$lib/state.svelte";
+  import {
+    state as _state,
+    selectNextEntry,
+    selectPreviousEntry,
+  } from "$lib/state.svelte";
   import {
     listWorkspaces,
     loadWorkspace,
@@ -27,6 +31,18 @@
 
   let workspaces: Workspace[] = $state([]);
 
+  window.addEventListener("keydown", (e) => {
+    if (e.ctrlKey && e.key === "o") {
+      selectPreviousEntry();
+      return;
+    }
+
+    if (e.ctrlKey && e.key === "i") {
+      selectNextEntry();
+      return;
+    }
+  });
+
   onMount(async () => {
     workspaces = await listWorkspaces();
     const lastEntry = await getSetting("lastEntry");