A simple CPU rendered GUI IDE experience.
Diffstat (limited to 'src/edi/input_handlers/click.rs')
| -rw-r--r-- | src/edi/input_handlers/click.rs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/edi/input_handlers/click.rs b/src/edi/input_handlers/click.rs new file mode 100644 index 0000000..0998d46 --- /dev/null +++ b/src/edi/input_handlers/click.rs @@ -0,0 +1,86 @@ +use std::sync::Arc; + +use rust_fsm::StateMachine; +use winit::event::MouseButton; +use winit::window::Window; + +use crate::edi::*; +impl Editor { + pub fn click( + &mut self, + bt: MouseButton, + cursor_position: (usize, usize), + w: Arc<dyn Window>, + ) { + let text = &mut self.text; + _ = self + .requests + .complete + .consume(CompletionAction::Click) + .unwrap(); + match self.state.consume(Action::M(bt)).unwrap() { + Some(Do::MoveCursor) => { + text.cursor.just( + text.mapped_index_at(cursor_position), + &text.rope, + ); + if let Some((lsp, path)) = lsp!(self + p) { + if self.requests.sig_help.result.is_some() { + self.requests.sig_help.request(lsp.runtime.spawn( + lsp.request_sig_help( + path, + text.primary_cursor(), + ), + )); + } + self.requests.document_highlights.request( + lsp.runtime.spawn( + lsp.document_highlights( + path, + text.to_l_position( + text.cursor.first().position, + ) + .unwrap(), + ), + ), + ); + } + self.hist.lc = text.cursor.clone(); + self.chist.push(text.primary_cursor()); + text.cursor.first().setc(&text.rope); + } + Some(Do::NavForward) => self.nav_forward(), + Some(Do::NavBack) => self.nav_back(), + Some(Do::ExtendSelectionToMouse) => { + let p = text.mapped_index_at(cursor_position); + text.cursor.first_mut().extend_selection_to(p, &text.rope); + } + Some(Do::StartSelection) => { + let p = text.mapped_index_at(cursor_position); + + let x = *text.cursor.first(); + text.cursor.first_mut().sel = Some((x..x).into()); + text.cursor.first_mut().extend_selection_to(p, &text.rope); + self.hist.lc = text.cursor.clone(); + } + Some(Do::GoToDefinition) => { + if let Some(x) = self.requests.def.result.clone() + && let Err(e) = self.go(&x, w.clone()) + { + log::error!("gtd: {e}"); + } + } + Some(Do::InsertCursorAtMouse) => { + text.cursor.add( + text.mapped_index_at(cursor_position), + &text.rope, + ); + self.hist.lc = text.cursor.clone(); + self.chist.push(text.primary_cursor()); + text.cursor.first().setc(&text.rope); + } + None => {} + _ => unreachable!(), + } + } +} |