Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting cursor #139

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/edit/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Cursor> {
self.select_opt
}
Expand Down
5 changes: 4 additions & 1 deletion src/edit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cursor>;

Expand Down
4 changes: 4 additions & 0 deletions src/edit/syntect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cursor> {
self.editor.select_opt()
}
Expand Down
4 changes: 4 additions & 0 deletions src/edit/vi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cursor> {
self.editor.select_opt()
}
Expand Down