|
|
|
@ -1,30 +1,225 @@
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use helix_view::Editor;
|
|
|
|
|
use helix_core::Position;
|
|
|
|
|
use helix_view::{
|
|
|
|
|
graphics::{Color, CursorKind, Rect, UnderlineStyle},
|
|
|
|
|
input::{Event, KeyEvent},
|
|
|
|
|
keyboard::{KeyCode, KeyModifiers},
|
|
|
|
|
theme::Style,
|
|
|
|
|
Editor,
|
|
|
|
|
};
|
|
|
|
|
use steel::{
|
|
|
|
|
rvals::{Custom, FromSteelVal, IntoSteelVal},
|
|
|
|
|
steel_vm::{builtin::BuiltInModule, engine::Engine, register_fn::RegisterFn},
|
|
|
|
|
steel_vm::{
|
|
|
|
|
builtin::BuiltInModule,
|
|
|
|
|
engine::Engine,
|
|
|
|
|
register_fn::{MarkerWrapper1, RegisterFn},
|
|
|
|
|
},
|
|
|
|
|
SteelVal,
|
|
|
|
|
};
|
|
|
|
|
use tui::{
|
|
|
|
|
buffer::Buffer,
|
|
|
|
|
widgets::{Block, BorderType, Borders, Widget},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
commands::{engine::steel::ENGINE, Context},
|
|
|
|
|
commands::{
|
|
|
|
|
engine::steel::{BoxDynComponent, ENGINE},
|
|
|
|
|
Context,
|
|
|
|
|
},
|
|
|
|
|
compositor::{self, Component},
|
|
|
|
|
ui::{Popup, Prompt, PromptEvent},
|
|
|
|
|
ctrl, key,
|
|
|
|
|
ui::{overlay::overlaid, Popup, Prompt, PromptEvent},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use super::steel::WrappedDynComponent;
|
|
|
|
|
|
|
|
|
|
// TODO: Move the main configuration function to use this instead
|
|
|
|
|
pub fn helix_component_module() -> BuiltInModule {
|
|
|
|
|
let mut module = BuiltInModule::new("helix/components".to_string());
|
|
|
|
|
|
|
|
|
|
module
|
|
|
|
|
.register_fn("frame-set-string!", buffer_set_string)
|
|
|
|
|
.register_fn("position", Position::new)
|
|
|
|
|
.register_fn("position-row", |position: &Position| position.row)
|
|
|
|
|
.register_fn("position-col", |position: &Position| position.col)
|
|
|
|
|
.register_fn("area", helix_view::graphics::Rect::new)
|
|
|
|
|
.register_fn("area-x", |area: &helix_view::graphics::Rect| area.x)
|
|
|
|
|
.register_fn("area-y", |area: &helix_view::graphics::Rect| area.y)
|
|
|
|
|
.register_fn("area-width", |area: &helix_view::graphics::Rect| area.width)
|
|
|
|
|
.register_fn("area-height", |area: &helix_view::graphics::Rect| {
|
|
|
|
|
area.height
|
|
|
|
|
})
|
|
|
|
|
.register_fn("overlaid", |component: &mut WrappedDynComponent| {
|
|
|
|
|
let inner: Option<Box<dyn Component>> = component
|
|
|
|
|
.inner
|
|
|
|
|
.take()
|
|
|
|
|
.map(|x| Box::new(overlaid(BoxDynComponent::new(x))) as Box<dyn Component>);
|
|
|
|
|
|
|
|
|
|
component.inner = inner;
|
|
|
|
|
})
|
|
|
|
|
.register_fn("block", || {
|
|
|
|
|
Block::default()
|
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
|
.border_style(Style::default().fg(Color::White))
|
|
|
|
|
.border_type(BorderType::Rounded)
|
|
|
|
|
.style(Style::default().bg(Color::Black))
|
|
|
|
|
})
|
|
|
|
|
.register_fn(
|
|
|
|
|
"block/render",
|
|
|
|
|
|buf: &mut Buffer, area: Rect, block: Block| block.render(area, buf),
|
|
|
|
|
)
|
|
|
|
|
.register_fn("buffer/clear", Buffer::clear)
|
|
|
|
|
.register_fn("buffer/clear-with", Buffer::clear_with)
|
|
|
|
|
.register_value("Color/Reset", Color::Reset.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Black", Color::Black.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Red", Color::Red.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/White", Color::White.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Green", Color::Green.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Yellow", Color::Yellow.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Blue", Color::Blue.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Magenta", Color::Magenta.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Cyan", Color::Cyan.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/Gray", Color::Gray.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/LightRed", Color::LightRed.into_steelval().unwrap())
|
|
|
|
|
.register_value(
|
|
|
|
|
"Color/LightGreen",
|
|
|
|
|
Color::LightGreen.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Color/LightYellow",
|
|
|
|
|
Color::LightYellow.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value("Color/LightBlue", Color::LightBlue.into_steelval().unwrap())
|
|
|
|
|
.register_value(
|
|
|
|
|
"Color/LightMagenta",
|
|
|
|
|
Color::LightMagenta.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value("Color/LightCyan", Color::LightCyan.into_steelval().unwrap())
|
|
|
|
|
.register_value("Color/LightGray", Color::LightGray.into_steelval().unwrap())
|
|
|
|
|
.register_fn("Color/rgb", Color::Rgb)
|
|
|
|
|
.register_fn("Color/Indexed", Color::Indexed)
|
|
|
|
|
.register_fn("style-fg", Style::fg)
|
|
|
|
|
.register_fn("style-bg", Style::bg)
|
|
|
|
|
.register_fn("style-underline-color", Style::underline_color)
|
|
|
|
|
.register_fn("style-underline-style", Style::underline_style)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Underline/Reset",
|
|
|
|
|
UnderlineStyle::Reset.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Underline/Line",
|
|
|
|
|
UnderlineStyle::Line.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Underline/Curl",
|
|
|
|
|
UnderlineStyle::Curl.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Underline/Dotted",
|
|
|
|
|
UnderlineStyle::Dotted.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Underline/Dashed",
|
|
|
|
|
UnderlineStyle::Dashed.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"Underline/DoubleLine",
|
|
|
|
|
UnderlineStyle::DoubleLine.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_fn("style", || Style::default())
|
|
|
|
|
.register_value(
|
|
|
|
|
"event-result/consume",
|
|
|
|
|
SteelEventResult::Consumed.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"event-result/ignore",
|
|
|
|
|
SteelEventResult::Ignored.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"event-result/close",
|
|
|
|
|
SteelEventResult::Close.into_steelval().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
// TODO: Use a reference here instead of passing by value.
|
|
|
|
|
.register_fn("key-event-char", |event: Event| {
|
|
|
|
|
if let Event::Key(event) = event {
|
|
|
|
|
event.char()
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.register_fn("key-event-modifier", |event: Event| {
|
|
|
|
|
if let Event::Key(KeyEvent { modifiers, .. }) = event {
|
|
|
|
|
Some(modifiers.bits())
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.register_value(
|
|
|
|
|
"key-modifier-ctrl",
|
|
|
|
|
SteelVal::IntV(KeyModifiers::CONTROL.bits() as isize),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"key-modifier-shift",
|
|
|
|
|
SteelVal::IntV(KeyModifiers::SHIFT.bits() as isize),
|
|
|
|
|
)
|
|
|
|
|
.register_value(
|
|
|
|
|
"key-modifier-alt",
|
|
|
|
|
SteelVal::IntV(KeyModifiers::ALT.bits() as isize),
|
|
|
|
|
)
|
|
|
|
|
.register_fn("key-event-escape?", |event: Event| {
|
|
|
|
|
if let Event::Key(KeyEvent {
|
|
|
|
|
code: KeyCode::Esc, ..
|
|
|
|
|
}) = event
|
|
|
|
|
{
|
|
|
|
|
true
|
|
|
|
|
} else {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.register_fn("key-event-backspace?", |event: Event| {
|
|
|
|
|
if let Event::Key(KeyEvent {
|
|
|
|
|
code: KeyCode::Backspace,
|
|
|
|
|
..
|
|
|
|
|
}) = event
|
|
|
|
|
{
|
|
|
|
|
true
|
|
|
|
|
} else {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.register_fn("key-event-enter?", |event: Event| {
|
|
|
|
|
if let Event::Key(KeyEvent {
|
|
|
|
|
code: KeyCode::Enter,
|
|
|
|
|
..
|
|
|
|
|
}) = event
|
|
|
|
|
{
|
|
|
|
|
true
|
|
|
|
|
} else {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A dynamic component, used for rendering thing
|
|
|
|
|
fn buffer_set_string(
|
|
|
|
|
buffer: &mut tui::buffer::Buffer,
|
|
|
|
|
x: u16,
|
|
|
|
|
y: u16,
|
|
|
|
|
string: steel::rvals::SteelString,
|
|
|
|
|
style: Style,
|
|
|
|
|
) {
|
|
|
|
|
buffer.set_string(x, y, string.as_str(), style)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A dynamic component, used for rendering
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
// TODO: Implement `trace` method for objects that hold steel vals
|
|
|
|
|
pub struct SteelDynamicComponent {
|
|
|
|
|
name: String,
|
|
|
|
|
// TODO: currently the component id requires using a &'static str,
|
|
|
|
|
// however in a world with dynamic components that might not be
|
|
|
|
|
// the case anymore
|
|
|
|
|
_name: String,
|
|
|
|
|
// This _should_ be a struct, but in theory can be whatever you want. It will be the first argument
|
|
|
|
|
// passed to the functions in the remainder of the struct.
|
|
|
|
|
state: SteelVal,
|
|
|
|
@ -33,6 +228,11 @@ pub struct SteelDynamicComponent {
|
|
|
|
|
render: SteelVal,
|
|
|
|
|
cursor: Option<SteelVal>,
|
|
|
|
|
required_size: Option<SteelVal>,
|
|
|
|
|
|
|
|
|
|
// Cached key event; we keep this around so that when sending
|
|
|
|
|
// events to the event handler, we can reuse the heap allocation
|
|
|
|
|
// instead of re-allocating for every event (which might be a lot)
|
|
|
|
|
key_event: Option<SteelVal>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SteelDynamicComponent {
|
|
|
|
@ -42,21 +242,16 @@ impl SteelDynamicComponent {
|
|
|
|
|
render: SteelVal,
|
|
|
|
|
h: HashMap<String, SteelVal>,
|
|
|
|
|
) -> Self {
|
|
|
|
|
// if let SteelVal::HashMapV(h) = functions {
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
name,
|
|
|
|
|
_name: name,
|
|
|
|
|
state,
|
|
|
|
|
render,
|
|
|
|
|
handle_event: h.get("handle_event").cloned(),
|
|
|
|
|
should_update: h.get("should_update").cloned(),
|
|
|
|
|
cursor: h.get("cursor").cloned(),
|
|
|
|
|
required_size: h.get("required_size").cloned(),
|
|
|
|
|
key_event: None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
// panic!("Implement better error handling")
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn new_dyn(
|
|
|
|
@ -102,67 +297,15 @@ impl Custom for SteelDynamicComponent {}
|
|
|
|
|
|
|
|
|
|
impl Custom for Box<dyn Component> {}
|
|
|
|
|
|
|
|
|
|
pub struct WrappedDynComponent {
|
|
|
|
|
inner: Option<Box<dyn Component>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Custom for WrappedDynComponent {}
|
|
|
|
|
|
|
|
|
|
struct BoxDynComponent {
|
|
|
|
|
inner: Box<dyn Component>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl BoxDynComponent {
|
|
|
|
|
pub fn new(inner: Box<dyn Component>) -> Self {
|
|
|
|
|
Self { inner }
|
|
|
|
|
}
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
enum SteelEventResult {
|
|
|
|
|
Consumed,
|
|
|
|
|
Ignored,
|
|
|
|
|
Close,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Component for BoxDynComponent {
|
|
|
|
|
fn handle_event(
|
|
|
|
|
&mut self,
|
|
|
|
|
_event: &helix_view::input::Event,
|
|
|
|
|
_ctx: &mut compositor::Context,
|
|
|
|
|
) -> compositor::EventResult {
|
|
|
|
|
self.inner.handle_event(_event, _ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn should_update(&self) -> bool {
|
|
|
|
|
self.inner.should_update()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn cursor(
|
|
|
|
|
&self,
|
|
|
|
|
_area: helix_view::graphics::Rect,
|
|
|
|
|
_ctx: &Editor,
|
|
|
|
|
) -> (
|
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
|
) {
|
|
|
|
|
self.inner.cursor(_area, _ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn required_size(&mut self, _viewport: (u16, u16)) -> Option<(u16, u16)> {
|
|
|
|
|
self.inner.required_size(_viewport)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
|
std::any::type_name::<Self>()
|
|
|
|
|
}
|
|
|
|
|
impl Custom for SteelEventResult {}
|
|
|
|
|
|
|
|
|
|
fn id(&self) -> Option<&'static str> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn render(
|
|
|
|
|
&mut self,
|
|
|
|
|
area: helix_view::graphics::Rect,
|
|
|
|
|
frame: &mut tui::buffer::Buffer,
|
|
|
|
|
ctx: &mut compositor::Context,
|
|
|
|
|
) {
|
|
|
|
|
self.inner.render(area, frame, ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Component for SteelDynamicComponent {
|
|
|
|
|
fn render(
|
|
|
|
|
&mut self,
|
|
|
|
@ -181,10 +324,10 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
|
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
|
// attempting to render
|
|
|
|
|
let thunk = |engine: &mut Engine, f, c| {
|
|
|
|
|
let thunk = |engine: &mut Engine, f| {
|
|
|
|
|
engine.call_function_with_args(
|
|
|
|
|
self.render.clone(),
|
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap(), f, c],
|
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap(), f],
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -196,16 +339,15 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
.consume(|engine, args| {
|
|
|
|
|
let mut arg_iter = args.into_iter();
|
|
|
|
|
|
|
|
|
|
(thunk)(engine, arg_iter.next().unwrap(), arg_iter.next().unwrap())
|
|
|
|
|
})
|
|
|
|
|
let buffer = arg_iter.next().unwrap();
|
|
|
|
|
let context = arg_iter.next().unwrap();
|
|
|
|
|
|
|
|
|
|
engine.update_value("*helix.cx*", context);
|
|
|
|
|
|
|
|
|
|
// .run_with_references::<tui::buffer::Buffer, tui::buffer::Buffer, Context, Context>(
|
|
|
|
|
// frame, &mut ctx, thunk,
|
|
|
|
|
// )
|
|
|
|
|
(thunk)(engine, buffer)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
log::info!("Calling dynamic render!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Pass in event as well? Need to have immutable reference type
|
|
|
|
@ -213,7 +355,7 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
// Clong is _not_ ideal, but it might be all we can do for now.
|
|
|
|
|
fn handle_event(
|
|
|
|
|
&mut self,
|
|
|
|
|
event: &helix_view::input::Event,
|
|
|
|
|
event: &Event,
|
|
|
|
|
ctx: &mut compositor::Context,
|
|
|
|
|
) -> compositor::EventResult {
|
|
|
|
|
if let Some(handle_event) = &mut self.handle_event {
|
|
|
|
@ -226,29 +368,70 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
jobs: ctx.jobs,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
log::info!("Handling custom event: {:?}", event);
|
|
|
|
|
|
|
|
|
|
match self.key_event.as_mut() {
|
|
|
|
|
Some(SteelVal::Custom(key_event)) => {
|
|
|
|
|
// Save the headache, reuse the allocation
|
|
|
|
|
if let Some(inner) = steel::rvals::as_underlying_type_mut::<Event>(
|
|
|
|
|
key_event.borrow_mut().as_mut(),
|
|
|
|
|
) {
|
|
|
|
|
*inner = event.clone();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None => {
|
|
|
|
|
self.key_event = Some(event.clone().into_steelval().unwrap());
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
panic!("This event needs to stay as a steelval");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
|
// attempting to render
|
|
|
|
|
let thunk = |engine: &mut Engine, c| {
|
|
|
|
|
let thunk = |engine: &mut Engine| {
|
|
|
|
|
engine.call_function_with_args(
|
|
|
|
|
handle_event.clone(),
|
|
|
|
|
vec![
|
|
|
|
|
self.state.clone(),
|
|
|
|
|
// TODO: We do _not_ want to clone here, we would need to create a bunch of methods on the engine for various
|
|
|
|
|
// combinations of reference passing to do this safely. Right now its limited to mutable references, but we should
|
|
|
|
|
// expose more - investigate macros on how to do that with recursively crunching the list to generate the combinations.
|
|
|
|
|
// Experimentation needed.
|
|
|
|
|
event.clone().into_steelval().unwrap(),
|
|
|
|
|
c,
|
|
|
|
|
],
|
|
|
|
|
vec![self.state.clone(), self.key_event.clone().unwrap()],
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let close_fn = compositor::EventResult::Consumed(Some(Box::new(
|
|
|
|
|
|compositor: &mut compositor::Compositor, _| {
|
|
|
|
|
// remove the layer
|
|
|
|
|
compositor.pop();
|
|
|
|
|
},
|
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
let event = match event {
|
|
|
|
|
Event::Key(event) => *event,
|
|
|
|
|
_ => return compositor::EventResult::Ignored(None),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match ENGINE.with(|x| {
|
|
|
|
|
x.borrow_mut()
|
|
|
|
|
.run_thunk_with_reference::<Context, Context>(&mut ctx, thunk)
|
|
|
|
|
.with_mut_reference::<Context, Context>(&mut ctx)
|
|
|
|
|
.consume(move |engine, arguments| {
|
|
|
|
|
let context = arguments[0].clone();
|
|
|
|
|
engine.update_value("*helix.cx*", context);
|
|
|
|
|
|
|
|
|
|
thunk(engine)
|
|
|
|
|
})
|
|
|
|
|
}) {
|
|
|
|
|
Ok(v) => compositor::EventResult::from_steelval(&v)
|
|
|
|
|
.unwrap_or_else(|_| compositor::EventResult::Ignored(None)),
|
|
|
|
|
Ok(v) => {
|
|
|
|
|
let value = SteelEventResult::from_steelval(&v);
|
|
|
|
|
|
|
|
|
|
match value {
|
|
|
|
|
Ok(SteelEventResult::Close) => close_fn,
|
|
|
|
|
Ok(SteelEventResult::Consumed) => compositor::EventResult::Consumed(None),
|
|
|
|
|
Ok(SteelEventResult::Ignored) => compositor::EventResult::Ignored(None),
|
|
|
|
|
_ => match event {
|
|
|
|
|
ctrl!('c') | key!(Esc) => close_fn,
|
|
|
|
|
_ => compositor::EventResult::Ignored(None),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(_) => compositor::EventResult::Ignored(None),
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -259,8 +442,11 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
fn should_update(&self) -> bool {
|
|
|
|
|
if let Some(should_update) = &self.should_update {
|
|
|
|
|
match ENGINE.with(|x| {
|
|
|
|
|
x.borrow_mut()
|
|
|
|
|
.call_function_with_args(should_update.clone(), vec![self.state.clone()])
|
|
|
|
|
let res = x
|
|
|
|
|
.borrow_mut()
|
|
|
|
|
.call_function_with_args(should_update.clone(), vec![self.state.clone()]);
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|
}) {
|
|
|
|
|
Ok(v) => bool::from_steelval(&v).unwrap_or(true),
|
|
|
|
|
Err(_) => true,
|
|
|
|
@ -274,30 +460,29 @@ impl Component for SteelDynamicComponent {
|
|
|
|
|
fn cursor(
|
|
|
|
|
&self,
|
|
|
|
|
area: helix_view::graphics::Rect,
|
|
|
|
|
ctx: &Editor,
|
|
|
|
|
_ctx: &Editor,
|
|
|
|
|
) -> (
|
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
|
) {
|
|
|
|
|
log::info!("Calling cursor with area: {:?}", area);
|
|
|
|
|
if let Some(cursor) = &self.cursor {
|
|
|
|
|
// Pass the `state` object through - this can be used for storing the state of whatever plugin thing we're
|
|
|
|
|
// attempting to render
|
|
|
|
|
let thunk = |engine: &mut Engine, e| {
|
|
|
|
|
let thunk = |engine: &mut Engine| {
|
|
|
|
|
engine.call_function_with_args(
|
|
|
|
|
cursor.clone(),
|
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap(), e],
|
|
|
|
|
vec![self.state.clone(), area.into_steelval().unwrap()],
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
<(
|
|
|
|
|
Option<helix_core::Position>,
|
|
|
|
|
helix_view::graphics::CursorKind,
|
|
|
|
|
)>::from_steelval(&ENGINE.with(|x| {
|
|
|
|
|
x.borrow_mut()
|
|
|
|
|
.run_thunk_with_ro_reference::<Editor, Editor>(ctx, thunk)
|
|
|
|
|
.unwrap()
|
|
|
|
|
}))
|
|
|
|
|
.unwrap()
|
|
|
|
|
let result = Option::<helix_core::Position>::from_steelval(
|
|
|
|
|
&ENGINE.with(|x| thunk(&mut (x.borrow_mut())).unwrap()),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
log::info!("Setting cursor at position: {:?}", result);
|
|
|
|
|
|
|
|
|
|
(result.unwrap(), CursorKind::Block)
|
|
|
|
|
} else {
|
|
|
|
|
(None, helix_view::graphics::CursorKind::Hidden)
|
|
|
|
|
}
|
|
|
|
|