Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/edit/src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,19 @@ impl Tui {
// On left-mouse-down we change focus.
let mut target = 0;
if next_state == InputMouseState::Left {
target = focused_node.map_or(0, |n| n.borrow().id);
Self::build_node_path(focused_node, &mut self.focused_node_path);
let mut focus_target = focused_node;
if let Some(node_cell) = focused_node {
let (node_id, node_depth, toggle) = {
let node = node_cell.borrow();
(node.id, node.depth, node.attributes.toggle_focus_on_click)
};
if toggle && self.is_subtree_focused_alt(node_id, node_depth) {
focus_target = None;
} else {
target = node_id;
}
}
Self::build_node_path(focus_target, &mut self.focused_node_path);
self.needs_more_settling(); // See `needs_more_settling()`.
}

Expand Down Expand Up @@ -3130,6 +3141,10 @@ impl<'a> Context<'a, '_> {
ButtonStyle::default().accelerator(accelerator).bracketed(false),
);
self.attr_focusable();
{
let mut last_node = self.tree.last_node.borrow_mut();
last_node.attributes.toggle_focus_on_click = true;
}
Comment on lines +3144 to +3147
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding toggle_focus_on_click I wonder if you could do something like this here:

if contains_focus && self.button_activated() {
    self.toss_focus_up();
    return false;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave it a try but it leads to the item immediately losing the focus again after releasing the mouse button.

self.attr_padding(Rect::two(0, 1));

let contains_focus = self.contains_focus();
Expand Down Expand Up @@ -3638,6 +3653,7 @@ struct NodeAttributes {
focusable: bool,
focus_well: bool, // Prevents focus from leaving via Tab
focus_void: bool, // Prevents focus from entering via Tab
toggle_focus_on_click: bool, // If true, clicking an already focused node removes focus from it
}

/// NOTE: Must not contain items that require drop().
Expand Down