diff options
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/completion.rs | 32 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 12 | ||||
-rw-r--r-- | helix-term/src/ui/mod.rs | 17 |
3 files changed, 45 insertions, 16 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 322e5b7b..9c753007 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -21,6 +21,7 @@ use lsp::CompletionItem; pub struct Completion { popup: Popup<Menu<CompletionItem>>, // TODO: Popup<Menu> need to be able to access contents. trigger_offset: usize, + // TODO: maintain a completioncontext with trigger kind & trigger char } impl Completion { @@ -43,7 +44,9 @@ impl Completion { // doc.state = snapshot.clone(); } PromptEvent::Validate => { - let id = editor.view().doc; + let view = editor.view(); + let view_id = view.id; + let id = view.doc; let doc = &mut editor.documents[id]; // revert state to what it was before the last update @@ -89,18 +92,18 @@ impl Completion { } // if more text was entered, remove it - let cursor = doc.selection().cursor(); + let cursor = doc.selection(view_id).cursor(); if trigger_offset < cursor { let remove = Transaction::change( doc.text(), vec![(trigger_offset, cursor, None)].into_iter(), ); - doc.apply(&remove); + doc.apply(&remove, view_id); } let transaction = util::generate_transaction_from_edits(doc.text(), vec![edit]); - doc.apply(&transaction); + doc.apply(&transaction, view_id); } _ => (), }; @@ -124,15 +127,32 @@ impl Component for Completion { { // recompute menu based on matches let menu = self.popup.contents(); - let id = cx.editor.view().doc; + let view = cx.editor.view(); + let view_id = view.id; + let id = view.doc; let doc = cx.editor.document(id).unwrap(); - let cursor = doc.selection().cursor(); + // cx.hooks() + // cx.add_hook(enum type, ||) + // cx.trigger_hook(enum type, &str, ...) <-- there has to be enough to identify doc/view + // callback with editor & compositor + // + // trigger_hook sends event into channel, that's consumed in the global loop and + // triggers all registered callbacks + // TODO: hooks should get processed immediately so maybe do it after select!(), before + // looping? + + let cursor = doc.selection(view_id).cursor(); if self.trigger_offset <= cursor { let fragment = doc.text().slice(self.trigger_offset..cursor); + // ^ problem seems to be that we handle events here before the editor layer, so the + // keypress isn't included in the editor layer yet... + // so we can't use ..= for now. let text = Cow::from(fragment); // TODO: logic is same as ui/picker menu.score(&text); + + // TODO: if after scoring the selection is 0 items, remove popup } } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 1f4bf6bd..7ceeb6ca 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -64,7 +64,7 @@ impl EditorView { // TODO: this seems to prevent setting style later // surface.set_style(viewport, theme.get("ui.background")); - self.render_diagnostics(&doc, area, surface, theme, is_focused); + self.render_diagnostics(&doc, view, area, surface, theme, is_focused); let area = Rect::new( viewport.x, @@ -224,7 +224,7 @@ impl EditorView { let selection_style = Style::default().bg(Color::Rgb(84, 0, 153)); for selection in doc - .selection() + .selection(view.id) .iter() .filter(|range| range.overlaps(&screen)) { @@ -332,6 +332,7 @@ impl EditorView { pub fn render_diagnostics( &self, doc: &Document, + view: &View, viewport: Rect, surface: &mut Surface, theme: &Theme, @@ -344,7 +345,7 @@ impl EditorView { widgets::{Paragraph, Widget}, }; - let cursor = doc.selection().cursor(); + let cursor = doc.selection(view.id).cursor(); let line = doc.text().char_to_line(cursor); let diagnostics = doc.diagnostics.iter().filter(|diagnostic| { @@ -486,11 +487,14 @@ impl Component for EditorView { EventResult::Consumed(None) } Event::Key(event) => { - let id = cx.editor.view().doc; + let view = cx.editor.view(); + let view_id = view.id; + let id = view.doc; let mode = cx.editor.document(id).unwrap().mode(); let mut cxt = commands::Context { editor: &mut cx.editor, + view_id, count: 1, callback: None, callbacks: cx.callbacks, diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 47c75d2f..341a30e0 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -35,7 +35,8 @@ pub fn regex_prompt( prompt: String, fun: impl Fn(&mut Document, Regex) + 'static, ) -> Prompt { - let snapshot = cx.doc().selection().clone(); + let view_id = cx.view().id; + let snapshot = cx.doc().selection(view_id).clone(); Prompt::new( prompt, @@ -44,9 +45,11 @@ pub fn regex_prompt( match event { PromptEvent::Abort => { // TODO: also revert text - let id = editor.view().doc; + let view = editor.view(); + let view_id = view.id; + let id = view.doc; let doc = &mut editor.documents[id]; - doc.set_selection(snapshot.clone()); + doc.set_selection(view_id, snapshot.clone()); } PromptEvent::Validate => { // TODO: push_jump to store selection just before jump @@ -60,16 +63,18 @@ pub fn regex_prompt( match Regex::new(input) { Ok(regex) => { // let view = &mut editor.view_mut(); - let id = editor.view().doc; + let view = editor.view(); + let view_id = view.id; + let id = view.doc; let doc = &mut editor.documents[id]; // revert state to what it was before the last update // TODO: also revert text - doc.set_selection(snapshot.clone()); + doc.set_selection(view_id, snapshot.clone()); fun(doc, regex); - editor.ensure_cursor_in_view(editor.view().id); + editor.ensure_cursor_in_view(view_id); } Err(_err) => (), // TODO: mark command line as error } |