Skip to main content

ferrum_flow/plugins/
history.rs

1use crate::plugin::{FlowEvent, Plugin, primary_platform_modifier};
2
3pub struct HistoryPlugin;
4
5impl HistoryPlugin {
6    pub fn new() -> Self {
7        Self {}
8    }
9}
10
11impl Plugin for HistoryPlugin {
12    fn name(&self) -> &'static str {
13        "history"
14    }
15    fn setup(&mut self, _ctx: &mut crate::plugin::InitPluginContext) {}
16    fn on_event(
17        &mut self,
18        event: &FlowEvent,
19        ctx: &mut crate::plugin::PluginContext,
20    ) -> crate::plugin::EventResult {
21        if let FlowEvent::Input(crate::plugin::InputEvent::KeyDown(ev)) = event {
22            let primary = primary_platform_modifier(ev);
23            if ev.keystroke.key == "z" && primary && ev.keystroke.modifiers.shift {
24                ctx.redo();
25                return crate::plugin::EventResult::Stop;
26            } else if ev.keystroke.key == "z" && primary {
27                ctx.undo();
28                return crate::plugin::EventResult::Stop;
29            }
30        }
31        crate::plugin::EventResult::Continue
32    }
33}