Skip to content

Commit

Permalink
Put cursor on title when double-clicking in tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Apr 28, 2024
1 parent ba07e81 commit 58bb4ae
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/model/listing/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ impl Cursor {
self.update_internal(document, UpdateMode::Default);
}

pub fn goto(&mut self, document: sync::Arc<document::Document>, 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<document::Document>, 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 {
Expand Down
3 changes: 2 additions & 1 deletion src/view/action/listing/navigate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
10 changes: 6 additions & 4 deletions src/view/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,19 @@ impl ListingWidget {
self.imp().interior.get().unwrap().write().cursor.bonk();
}

pub fn goto(&self, document: &sync::Arc<document::Document>, path: &structure::Path, offset: addr::Address) {
pub fn goto(&self, document: &sync::Arc<document::Document>, 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<document::Document>) {
Expand Down
4 changes: 2 additions & 2 deletions src/view/listing/facet/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<document::Document>, path: &structure::Path, offset: addr::Address) -> Result<(), cursor::PlacementFailure> {
pub fn goto(&mut self, document: sync::Arc<document::Document>, 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)
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/view/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 58bb4ae

Please sign in to comment.