Skip to content

Commit 40e42d0

Browse files
committed
Update to cursive-core 0.3.0
1 parent 2c734a5 commit 40e42d0

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ repository = "https://github.com/deinstapel/cursive-multiplex"
1111
version = "0.5.2-alpha.0"
1212

1313
[dependencies]
14-
cursive_core = "0.2"
14+
cursive_core = "0.3"
1515
thiserror = "1.0"
1616
indextree = "4.3"
1717
log = "0.4"
1818

1919
[dev-dependencies]
2020
crossbeam = "0.8"
21-
cursive = "0.16"
21+
cursive = "0.17"
2222
serde_json = "1.0"
2323
insta = "1.7"

src/actions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl Mux {
4545
// Traverse the path down again
4646
if let Some(focus) = self.traverse_search_path(path, turn_point, direction, origin)
4747
{
48-
if self.tree.get_mut(focus).unwrap().get_mut().take_focus() {
48+
if let Ok(result) = self.tree.get_mut(focus).unwrap().get_mut().take_focus() {
4949
self.focus = focus;
50-
EventResult::Consumed(None)
50+
EventResult::Consumed(None).and(result)
5151
} else {
5252
// rejected
5353
self.move_focus_relative(direction, focus, origin)

src/id.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,16 @@ impl Mux {
229229
debug!("Changed order");
230230
}
231231

232-
if self.tree.get_mut(new_node).unwrap().get_mut().take_focus() {
232+
if self
233+
.tree
234+
.get_mut(new_node)
235+
.unwrap()
236+
.get_mut()
237+
.take_focus()
238+
.is_ok()
239+
{
240+
// Here we discard the potential callback from the focused view.
241+
// Ideally we would bubble it up so it can be processed.
233242
self.focus = new_node;
234243
debug!("Changed Focus: {}", new_node);
235244
}

src/lib.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod path;
4242

4343
use cursive_core::direction::{Absolute, Direction};
4444
use cursive_core::event::{AnyCb, Event, EventResult, Key, MouseButton, MouseEvent};
45-
use cursive_core::view::{Selector, View, ViewNotFound};
45+
use cursive_core::view::{CannotFocus, Selector, View, ViewNotFound};
4646
use cursive_core::{Printer, Vec2};
4747
pub use error::*;
4848
pub use id::Id;
@@ -111,12 +111,12 @@ impl View for Mux {
111111
}
112112
}
113113

114-
fn take_focus(&mut self, _source: Direction) -> bool {
115-
true
114+
fn take_focus(&mut self, _source: Direction) -> Result<EventResult, CannotFocus> {
115+
Ok(EventResult::consumed())
116116
}
117117

118-
fn focus_view(&mut self, _: &Selector) -> Result<(), ViewNotFound> {
119-
Ok(())
118+
fn focus_view(&mut self, _: &Selector) -> Result<EventResult, ViewNotFound> {
119+
Ok(EventResult::consumed())
120120
}
121121

122122
fn call_on_any<'a>(&mut self, slct: &Selector, cb: AnyCb<'a>) {
@@ -130,6 +130,7 @@ impl View for Mux {
130130

131131
fn on_event(&mut self, evt: Event) -> EventResult {
132132
// pre_check if focus has to be changed, we dont want views react to mouse click out of their reach
133+
let mut result = EventResult::Ignored;
133134
if let Event::Mouse {
134135
offset,
135136
position,
@@ -138,20 +139,23 @@ impl View for Mux {
138139
{
139140
if let Some(off_pos) = position.checked_sub(offset) {
140141
if let Some(pane) = self.clicked_pane(off_pos) {
141-
if self.tree.get_mut(pane).unwrap().get_mut().take_focus() && self.focus != pane
142-
{
143-
self.focus = pane;
144-
self.invalidated = true;
142+
if let Ok(res) = self.tree.get_mut(pane).unwrap().get_mut().take_focus() {
143+
if self.focus != pane {
144+
result = res;
145+
self.focus = pane;
146+
self.invalidated = true;
147+
}
145148
}
146149
}
147150
}
148151
}
149-
let result = self
150-
.tree
151-
.get_mut(self.focus)
152-
.unwrap()
153-
.get_mut()
154-
.on_event(evt.clone(), self.zoomed);
152+
let result = result.and(
153+
self.tree
154+
.get_mut(self.focus)
155+
.unwrap()
156+
.get_mut()
157+
.on_event(evt.clone(), self.zoomed),
158+
);
155159
match result {
156160
EventResult::Ignored => match evt {
157161
_ if self.focus_left == evt => self.move_focus(Absolute::Left),

src/node.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::error::RenderError;
22
use crate::{AnyCb, Direction, Event, EventResult, Orientation, Printer, Selector, Vec2, View};
33
use cursive_core::direction::Absolute;
4+
use cursive_core::view::CannotFocus;
45

56
pub(crate) struct Node {
67
pub(crate) view: Option<Box<dyn View>>,
@@ -159,11 +160,11 @@ impl Node {
159160
}
160161
}
161162

162-
pub(crate) fn take_focus(&mut self) -> bool {
163+
pub(crate) fn take_focus(&mut self) -> Result<EventResult, CannotFocus> {
163164
if let Some(view) = self.view.as_mut() {
164165
view.take_focus(Direction::none())
165166
} else {
166-
false
167+
Err(CannotFocus)
167168
}
168169
}
169170

0 commit comments

Comments
 (0)