mirror of https://github.com/helix-editor/helix
add ability to ignore the command and close the component
parent
67c5a2a99b
commit
aada3b5e42
|
@ -1319,6 +1319,18 @@ will not continue to be propagated down the component stack. This will _not_ tri
|
||||||
a re-render.
|
a re-render.
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
register!(
|
||||||
|
value,
|
||||||
|
"event-result/ignore-and-close",
|
||||||
|
SteelEventResult::IgnoreAndClose.into_steelval().unwrap(),
|
||||||
|
r#"
|
||||||
|
Singleton for ignoring an event. If this is returned from an event handler, the event
|
||||||
|
will continue to be propagated down the component stack, and the component will be
|
||||||
|
popped off of the stack and removed.
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
register!(
|
register!(
|
||||||
value,
|
value,
|
||||||
"event-result/close",
|
"event-result/close",
|
||||||
|
@ -1742,6 +1754,7 @@ impl Custom for Box<dyn Component> {}
|
||||||
enum SteelEventResult {
|
enum SteelEventResult {
|
||||||
Consumed,
|
Consumed,
|
||||||
Ignored,
|
Ignored,
|
||||||
|
IgnoreAndClose,
|
||||||
Close,
|
Close,
|
||||||
ConsumedWithoutRerender,
|
ConsumedWithoutRerender,
|
||||||
}
|
}
|
||||||
|
@ -1850,13 +1863,6 @@ impl Component for SteelDynamicComponent {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let close_fn = compositor::EventResult::Consumed(Some(Box::new(
|
|
||||||
|compositor: &mut compositor::Compositor, _| {
|
|
||||||
// remove the layer
|
|
||||||
compositor.pop();
|
|
||||||
},
|
|
||||||
)));
|
|
||||||
|
|
||||||
// let event = match event {
|
// let event = match event {
|
||||||
// Event::Key(event) => *event,
|
// Event::Key(event) => *event,
|
||||||
// _ => return compositor::EventResult::Ignored(None),
|
// _ => return compositor::EventResult::Ignored(None),
|
||||||
|
@ -1876,12 +1882,23 @@ impl Component for SteelDynamicComponent {
|
||||||
let value = SteelEventResult::from_steelval(&v);
|
let value = SteelEventResult::from_steelval(&v);
|
||||||
|
|
||||||
match value {
|
match value {
|
||||||
Ok(SteelEventResult::Close) => close_fn,
|
Ok(SteelEventResult::Close) => compositor::EventResult::Consumed(Some(
|
||||||
|
Box::new(|compositor: &mut compositor::Compositor, _| {
|
||||||
|
// remove the layer
|
||||||
|
compositor.pop();
|
||||||
|
}),
|
||||||
|
)),
|
||||||
Ok(SteelEventResult::Consumed) => compositor::EventResult::Consumed(None),
|
Ok(SteelEventResult::Consumed) => compositor::EventResult::Consumed(None),
|
||||||
Ok(SteelEventResult::ConsumedWithoutRerender) => {
|
Ok(SteelEventResult::ConsumedWithoutRerender) => {
|
||||||
compositor::EventResult::ConsumedWithoutRerender
|
compositor::EventResult::ConsumedWithoutRerender
|
||||||
}
|
}
|
||||||
Ok(SteelEventResult::Ignored) => compositor::EventResult::Ignored(None),
|
Ok(SteelEventResult::Ignored) => compositor::EventResult::Ignored(None),
|
||||||
|
Ok(SteelEventResult::IgnoreAndClose) => compositor::EventResult::Ignored(
|
||||||
|
Some(Box::new(|compositor: &mut compositor::Compositor, _| {
|
||||||
|
// remove the layer
|
||||||
|
compositor.pop();
|
||||||
|
})),
|
||||||
|
),
|
||||||
_ => match event {
|
_ => match event {
|
||||||
// ctrl!('c') | key!(Esc) => close_fn,
|
// ctrl!('c') | key!(Esc) => close_fn,
|
||||||
_ => compositor::EventResult::Ignored(None),
|
_ => compositor::EventResult::Ignored(None),
|
||||||
|
|
Loading…
Reference in New Issue