diff options
author | Blaž Hrastnik | 2021-01-21 07:55:46 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-01-21 07:55:46 +0000 |
commit | 05c7fb98df43f7843d441e0dce3e5b361f2d7645 (patch) | |
tree | fef6ec32ba050d59538fa2d6ee8a7a64a36c4610 /helix-term/src/ui | |
parent | 15dd7ca6d863735db164456f78980a71fc8501a3 (diff) |
Refactoring: move language_servers into Editor, proper load for doc.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/editor.rs | 82 | ||||
-rw-r--r-- | helix-term/src/ui/mod.rs | 8 |
2 files changed, 43 insertions, 47 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index fced9acb..a97ee713 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -251,55 +251,52 @@ impl Component for EditorView { Event::Resize(width, height) => { // TODO: simplistic ensure cursor in view for now // TODO: loop over views - if let Some(view) = cx.editor.view_mut() { - view.size = (width, height); - view.ensure_cursor_in_view() - }; + let view = cx.editor.view_mut(); + view.size = (width, height); + view.ensure_cursor_in_view(); EventResult::Consumed(None) } Event::Key(event) => { - if let Some(view) = cx.editor.view_mut() { - let keys = vec![event]; - // TODO: sequences (`gg`) - let mode = view.doc.mode(); - // TODO: handle count other than 1 - let mut cx = commands::Context { - view, - executor: cx.executor, - language_servers: cx.language_servers, - count: 1, - callback: None, - }; + let view = cx.editor.view_mut(); + + let keys = vec![event]; + // TODO: sequences (`gg`) + let mode = view.doc.mode(); + // TODO: handle count other than 1 + let mut cxt = commands::Context { + executor: cx.executor, + editor: &mut cx.editor, + count: 1, + callback: None, + }; - match mode { - Mode::Insert => { - if let Some(command) = self.keymap[&Mode::Insert].get(&keys) { - command(&mut cx); - } else if let KeyEvent { - code: KeyCode::Char(c), - .. - } = event - { - commands::insert::insert_char(&mut cx, c); - } + match mode { + Mode::Insert => { + if let Some(command) = self.keymap[&Mode::Insert].get(&keys) { + command(&mut cxt); + } else if let KeyEvent { + code: KeyCode::Char(c), + .. + } = event + { + commands::insert::insert_char(&mut cxt, c); } - mode => { - if let Some(command) = self.keymap[&mode].get(&keys) { - command(&mut cx); + } + mode => { + if let Some(command) = self.keymap[&mode].get(&keys) { + command(&mut cxt); - // TODO: simplistic ensure cursor in view for now - } + // TODO: simplistic ensure cursor in view for now } } - // appease borrowck - let callback = cx.callback.take(); + } - view.ensure_cursor_in_view(); + // appease borrowck + let callback = cxt.callback.take(); + drop(cxt); + cx.editor.view_mut().ensure_cursor_in_view(); - EventResult::Consumed(callback) - } else { - EventResult::Ignored - } + EventResult::Consumed(callback) } Event::Mouse(_) => EventResult::Ignored, } @@ -309,9 +306,8 @@ impl Component for EditorView { // SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow // theme. Theme is immutable mutating view won't disrupt theme_ref. let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) }; - if let Some(view) = cx.editor.view_mut() { - self.render_view(view, area, surface, theme_ref); - } + let view = cx.editor.view_mut(); + self.render_view(view, area, surface, theme_ref); // TODO: drop unwrap } @@ -321,7 +317,7 @@ impl Component for EditorView { // Mode::Insert => write!(stdout, "\x1B[6 q"), // mode => write!(stdout, "\x1B[2 q"), // }; - let view = ctx.editor.view().unwrap(); + let view = ctx.editor.view(); let cursor = view.doc.state.selection().cursor(); let mut pos = view diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 4daf82fc..5ef967b0 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -16,7 +16,7 @@ pub fn text_color() -> Style { } use std::path::{Path, PathBuf}; -pub fn file_picker(root: &str) -> Picker<PathBuf> { +pub fn file_picker(root: &str, ex: &'static smol::Executor) -> Picker<PathBuf> { use ignore::Walk; // TODO: determine root based on git root let files = Walk::new(root).filter_map(|entry| match entry { @@ -40,9 +40,9 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> { // format_fn path.strip_prefix("./").unwrap().to_str().unwrap().into() }, - |editor: &mut Editor, path: &PathBuf| { - let size = editor.view().unwrap().size; - editor.open(path.into(), size); + move |editor: &mut Editor, path: &PathBuf| { + let size = editor.view().size; + editor.open(path.into(), size, ex); }, ) } |