From 6dba04df0898d7cbcf4bc89e58aab98d57a7c68c Mon Sep 17 00:00:00 2001 From: Dima Rets Date: Sat, 10 Jun 2023 12:38:14 +0100 Subject: [PATCH] allow setting cursor --- src/edit/editor.rs | 15 ++++----------- src/edit/mod.rs | 5 ++++- src/edit/syntect.rs | 4 ++++ src/edit/vi.rs | 4 ++++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/edit/editor.rs b/src/edit/editor.rs index 2c7d5c3f3e..65b2aa62eb 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -36,17 +36,6 @@ impl Editor { } } - /// Create a new [`Editor`] with the provided [`Buffer`] and [`Cursor`] - pub fn new_with_cursor(buffer: Buffer, cursor: Cursor) -> Self { - Self { - buffer, - cursor, - cursor_x_opt: None, - select_opt: None, - cursor_moved: false, - } - } - fn set_layout_cursor(&mut self, font_system: &mut FontSystem, cursor: LayoutCursor) { let layout = self .buffer @@ -95,6 +84,10 @@ impl Edit for Editor { self.cursor } + fn set_cursor(&mut self, cursor: Cursor) { + self.cursor = cursor; + } + fn select_opt(&self) -> Option { self.select_opt } diff --git a/src/edit/mod.rs b/src/edit/mod.rs index 15ed8f38b1..77e07e3d03 100644 --- a/src/edit/mod.rs +++ b/src/edit/mod.rs @@ -99,9 +99,12 @@ pub trait Edit { /// Get the internal [`Buffer`], mutably fn buffer_mut(&mut self) -> &mut Buffer; - /// Get the current cursor position + /// Get the current cursor fn cursor(&self) -> Cursor; + /// Set the current cursor + fn set_cursor(&mut self, cursor: Cursor); + /// Get the current selection position fn select_opt(&self) -> Option; diff --git a/src/edit/syntect.rs b/src/edit/syntect.rs index 2c57ca5a20..6187a9d7c2 100644 --- a/src/edit/syntect.rs +++ b/src/edit/syntect.rs @@ -130,6 +130,10 @@ impl<'a> Edit for SyntaxEditor<'a> { self.editor.cursor() } + fn set_cursor(&mut self, cursor: Cursor) { + self.editor.set_cursor(cursor); + } + fn select_opt(&self) -> Option { self.editor.select_opt() } diff --git a/src/edit/vi.rs b/src/edit/vi.rs index 690edd399d..90b87dd938 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -64,6 +64,10 @@ impl<'a> Edit for ViEditor<'a> { self.editor.cursor() } + fn set_cursor(&mut self, cursor: Cursor) { + self.editor.set_cursor(cursor); + } + fn select_opt(&self) -> Option { self.editor.select_opt() }