From 58bb4aeae480400dda13e497ad186905331ee49b Mon Sep 17 00:00:00 2001 From: misson20000 Date: Sat, 27 Apr 2024 23:19:32 -0400 Subject: [PATCH] Put cursor on title when double-clicking in tree view --- src/model/listing/cursor.rs | 4 ++-- src/view/action/listing/navigate.rs | 3 ++- src/view/listing.rs | 10 ++++++---- src/view/listing/facet/cursor.rs | 4 ++-- src/view/window.rs | 3 ++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/model/listing/cursor.rs b/src/model/listing/cursor.rs index 73eeb14..85efd7d 100644 --- a/src/model/listing/cursor.rs +++ b/src/model/listing/cursor.rs @@ -193,8 +193,8 @@ impl Cursor { self.update_internal(document, UpdateMode::Default); } - pub fn goto(&mut self, document: sync::Arc, path: &structure::Path, offset: addr::Address) -> Result<(), PlacementFailure> { - Self::place(document, path, offset, PlacementHint::Unused).map(|new| { *self = new; }) + pub fn goto(&mut self, document: sync::Arc, path: &structure::Path, offset: addr::Address, hint: PlacementHint) -> Result<(), PlacementFailure> { + Self::place(document, path, offset, hint).map(|new| { *self = new; }) } pub fn is_over(&self, token: token::TokenRef<'_>) -> bool { diff --git a/src/view/action/listing/navigate.rs b/src/view/action/listing/navigate.rs index acdc801..5b4dcae 100644 --- a/src/view/action/listing/navigate.rs +++ b/src/view/action/listing/navigate.rs @@ -6,6 +6,7 @@ use std::sync; use crate::model::addr; use crate::model::document; use crate::model::document::search; +use crate::model::listing::cursor; use crate::view::helpers; use crate::view::listing; use crate::view::window; @@ -137,7 +138,7 @@ impl NavigateAction { let item_interior = item.imp().interior.get().unwrap(); - self.lw.goto(&item_interior.document, &item_interior.hit.path, item_interior.hit.offset.to_addr()); + self.lw.goto(&item_interior.document, &item_interior.hit.path, item_interior.hit.offset.to_addr(), cursor::PlacementHint::Unused); self.dialog.hide(); diff --git a/src/view/listing.rs b/src/view/listing.rs index 15bf4a1..bf635b7 100644 --- a/src/view/listing.rs +++ b/src/view/listing.rs @@ -398,17 +398,19 @@ impl ListingWidget { self.imp().interior.get().unwrap().write().cursor.bonk(); } - pub fn goto(&self, document: &sync::Arc, path: &structure::Path, offset: addr::Address) { + pub fn goto(&self, document: &sync::Arc, path: &structure::Path, offset: addr::Address, hint: cursor::PlacementHint) { let mut interior_guard = self.imp().interior.get().unwrap().write(); let interior = &mut *interior_guard; if interior.document.generation() != document.generation() { - self.bonk(); + interior.cursor.bonk(); return; } - interior.cursor.goto(document.clone(), path, offset).expect("lost cursor"); - interior.scroll.ensure_cursor_is_in_view(&mut interior.window, &mut interior.cursor, facet::scroll::EnsureCursorInViewDirection::Any) + interior.cursor.goto(document.clone(), path, offset, hint).expect("lost cursor"); + interior.scroll.ensure_cursor_is_in_view(&mut interior.window, &mut interior.cursor, facet::scroll::EnsureCursorInViewDirection::Any); + + self.queue_draw(); } fn document_updated(&self, new_document: &sync::Arc) { diff --git a/src/view/listing/facet/cursor.rs b/src/view/listing/facet/cursor.rs index df6353b..9b19bc1 100644 --- a/src/view/listing/facet/cursor.rs +++ b/src/view/listing/facet/cursor.rs @@ -142,9 +142,9 @@ impl CursorView { //pub fn move_up_to_break(&mut self) { self.movement(|c| c.move_up_to_break()); } //pub fn move_down_to_break(&mut self) { self.movement(|c| c.move_down_to_break()); } - pub fn goto(&mut self, document: sync::Arc, path: &structure::Path, offset: addr::Address) -> Result<(), cursor::PlacementFailure> { + pub fn goto(&mut self, document: sync::Arc, path: &structure::Path, offset: addr::Address, hint: cursor::PlacementHint) -> Result<(), cursor::PlacementFailure> { self.blink(); - self.cursor.goto(document, path, offset) + self.cursor.goto(document, path, offset, hint) } /* diff --git a/src/view/window.rs b/src/view/window.rs index 89cf97d..9629164 100644 --- a/src/view/window.rs +++ b/src/view/window.rs @@ -6,6 +6,7 @@ use crate::view::CharmApplication; use crate::model::addr; use crate::model::datapath; use crate::model::document; +use crate::model::listing::cursor; use crate::model::selection as selection_model; use crate::model::space; use crate::view; @@ -254,7 +255,7 @@ impl CharmWindow { let info = node_item.info(); - ctx.lw.goto(&info.document, &info.path, addr::unit::NULL); + ctx.lw.goto(&info.document, &info.path, addr::unit::NULL, cursor::PlacementHint::Title); })); /* window actions */