gardesk/garfield / f40ccb7

Browse files

ui: canonicalize paths for bookmark comparison

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
f40ccb78f17c88b892eb5306d2a7c587ba04c4b2
Parents
57f49e0
Tree
5bc5bd5

1 changed file

StatusFile+-
M garfield/src/ui/sidebar.rs 20 7
garfield/src/ui/sidebar.rsmodified
@@ -216,25 +216,32 @@ impl Sidebar {
216216
 
217217
     /// Add a bookmark for the given path. Returns true if added.
218218
     pub fn add_bookmark(&mut self, path: &Path) -> bool {
219
+        // Canonicalize the path for consistent comparison
220
+        let canonical = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
221
+
219222
         // Check if already bookmarked
220
-        if self.bookmarks.iter().any(|b| b.path == path) {
223
+        if self.bookmarks.iter().any(|b| {
224
+            b.path.canonicalize().unwrap_or_else(|_| b.path.clone()) == canonical
225
+        }) {
221226
             return false;
222227
         }
223228
 
224229
         // Check if it's a default place
225
-        if self.places.iter().any(|p| p.path == path) {
230
+        if self.places.iter().any(|p| {
231
+            p.path.canonicalize().unwrap_or_else(|_| p.path.clone()) == canonical
232
+        }) {
226233
             return false;
227234
         }
228235
 
229
-        let name = path
236
+        let name = canonical
230237
             .file_name()
231238
             .map(|s| s.to_string_lossy().to_string())
232
-            .unwrap_or_else(|| path.to_string_lossy().to_string());
239
+            .unwrap_or_else(|| canonical.to_string_lossy().to_string());
233240
 
234241
         self.bookmarks.push(Place {
235242
             name,
236243
             icon: "*".to_string(),
237
-            path: path.to_path_buf(),
244
+            path: canonical,
238245
             bounds: Rect::new(0, 0, 0, 0),
239246
             is_bookmark: true,
240247
         });
@@ -245,8 +252,11 @@ impl Sidebar {
245252
 
246253
     /// Remove a bookmark by path. Returns true if removed.
247254
     pub fn remove_bookmark(&mut self, path: &Path) -> bool {
255
+        let canonical = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
248256
         let initial_len = self.bookmarks.len();
249
-        self.bookmarks.retain(|b| b.path != path);
257
+        self.bookmarks.retain(|b| {
258
+            b.path.canonicalize().unwrap_or_else(|_| b.path.clone()) != canonical
259
+        });
250260
 
251261
         if self.bookmarks.len() != initial_len {
252262
             self.save_bookmarks();
@@ -258,7 +268,10 @@ impl Sidebar {
258268
 
259269
     /// Check if a path is bookmarked.
260270
     pub fn is_bookmarked(&self, path: &Path) -> bool {
261
-        self.bookmarks.iter().any(|b| b.path == path)
271
+        let canonical = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
272
+        self.bookmarks.iter().any(|b| {
273
+            b.path.canonicalize().unwrap_or_else(|_| b.path.clone()) == canonical
274
+        })
262275
     }
263276
 
264277
     /// Toggle bookmark for a path.