diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 19:06:46 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 19:06:46 +0200 |
| commit | 63cfcbe7a7745b276de58ec92e0141b958c44feb (patch) | |
| tree | 990e33a83756e27187033579ee2f85d5c79169d5 /src/state/editor/mod.rs | |
| parent | b747ca8af52129876b577a4f20f7105a05c6b002 (diff) | |
use unsafe blocks instead of mutexes
Diffstat (limited to 'src/state/editor/mod.rs')
| -rw-r--r-- | src/state/editor/mod.rs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/state/editor/mod.rs b/src/state/editor/mod.rs index 3639226..3e9d9e0 100644 --- a/src/state/editor/mod.rs +++ b/src/state/editor/mod.rs @@ -19,13 +19,7 @@ pub struct EditorState { macro_rules! cfg { () => { - GlobalState::instance().editor - }; -} - -macro_rules! cfg_mut { - () => { - GlobalState::instance_mut().editor + GlobalState::get().editor }; } @@ -51,12 +45,11 @@ impl UserData for EditorState { fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) { fields.add_field_function_get("visible", |_, _| Ok(cfg!().visible)); fields.add_field_function_set("visible", |_, _, visible: bool| { - let mut state = GlobalState::instance_mut(); - state.editor.visible = visible; + cfg!().visible = visible; - if let Window::Editor = state.active_window { + if let Window::Editor = GlobalState::get().active_window { if !visible { - state.set_focus(Window::View); + GlobalState::get().set_focus(Window::View); } } @@ -65,17 +58,16 @@ impl UserData for EditorState { fields.add_field_function_get("content", |_, _| Ok(cfg!().buffer.as_string())); fields.add_field_function_set("content", |_, _, content: String| { - cfg_mut!().buffer.set_lines_from_string(content); + cfg!().buffer.set_lines_from_string(content); Ok(()) }); fields.add_field_function_get("cursor_shape", |_, _| Ok(cfg!().cursor_shape)); fields.add_field_function_set("cursor_shape", |_, _, shape: CursorShape| { - cfg_mut!().cursor_shape = shape; + cfg!().cursor_shape = shape; Ok(()) }); - fields.add_field_function_get("lines", |lua, _| { let table = lua.create_table()?; @@ -86,7 +78,7 @@ impl UserData for EditorState { Ok(table) }); fields.add_field_function_set("lines", |_, _, content: String| { - cfg_mut!().buffer.set_lines_from_string(content); + cfg!().buffer.set_lines_from_string(content); Ok(()) }); @@ -100,7 +92,7 @@ impl UserData for EditorState { }); methods.add_function("move_cursor", |_, m: CursorMove| { - cfg_mut!().buffer.move_cursor(m); + cfg!().buffer.move_cursor(m); Ok(()) }) } |