diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 6e037a471..6ee721486 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -567,6 +567,14 @@ impl MappableCommand { command_palette, "Open command palette", goto_word, "Jump to a two-character label", extend_to_word, "Extend to a two-character label", + add_mark_file, "Bookmark a file", + add_mark_line, "Bookmark a perticular line in a file", + remove_mark_file, "Remove current file Bookmark if it exists", + remove_mark_line, "Remove current line Bookmark if it exists", + goto_nth_mark, "Move cursor to the Nth bookmark", + goto_next_mark, "Move cursor to the next bookmark", + goto_prev_mark, "Move cursor to the prev bookmark", + mark_picker, "Open mark picker", ); } @@ -6121,6 +6129,31 @@ fn goto_word(cx: &mut Context) { fn extend_to_word(cx: &mut Context) { jump_to_word(cx, Movement::Extend) } +fn add_mark_file(cx: &mut Context) { + todo!(); +} +fn add_mark_line(cx: &mut Context) { + todo!(); +} +fn remove_mark_file(cx: &mut Context) { + todo!(); +} +fn remove_mark_line(cx: &mut Context) { + todo!(); +} +fn goto_nth_mark(cx: &mut Context) { + todo!(); +} +fn goto_next_mark(cx: &mut Context) { + todo!(); +} +fn goto_prev_mark(cx: &mut Context) { + todo!(); +} + +fn mark_picker(cx: &mut Context) { + todo!(); +} fn jump_to_label(cx: &mut Context, labels: Vec, behaviour: Movement) { let doc = doc!(cx.editor); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 1708b3b4e..b17f1092d 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -680,6 +680,8 @@ pub enum GutterType { Spacer, /// Highlight local changes Diff, + /// Bookmarks + Mark, } impl std::str::FromStr for GutterType { diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index 36f719f79..709da856a 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -32,6 +32,7 @@ impl GutterType { GutterType::LineNumbers => line_numbers(editor, doc, view, theme, is_focused), GutterType::Spacer => padding(editor, doc, view, theme, is_focused), GutterType::Diff => diff(editor, doc, view, theme, is_focused), + GutterType::Mark => mark(editor, doc, view, theme, is_focused), } } @@ -41,6 +42,7 @@ impl GutterType { GutterType::LineNumbers => line_numbers_width(view, doc), GutterType::Spacer => 1, GutterType::Diff => 1, + GutterType::Mark => 1, } } } @@ -86,6 +88,16 @@ pub fn diagnostic<'doc>( ) } +pub fn mark<'doc>( + _editor: &'doc Editor, + doc: &'doc Document, + _view: &View, + theme: &Theme, + _is_focused: bool, +) -> GutterFn<'doc> { + todo!() +} + pub fn diff<'doc>( _editor: &'doc Editor, doc: &'doc Document, diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index a229f01ea..c0d850fdc 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -24,8 +24,54 @@ use std::{ }; const JUMP_LIST_CAPACITY: usize = 30; +const MARK_LIST_CAPACITY: usize = 30; type Jump = (DocumentId, Selection); +type Mark = (DocumentId, Selection); + +#[derive(Debug, Clone)] +pub struct MarkList { + marks: VecDeque, + current: usize, +} + +impl MarkList { + pub fn new(initial: Jump) -> Self { + todo!(); + } + + pub fn push(&mut self, jump: Jump) { + todo!() + } + + pub fn forward(&mut self, count: usize) -> Option<&Jump> { + todo!(); + } + + // Taking view and doc to prevent unnecessary cloning when jump is not required. + pub fn backward(&mut self, view_id: ViewId, doc: &mut Document, count: usize) -> Option<&Jump> { + todo!(); + } + + pub fn nth(&mut self, view_id: ViewId, doc: &mut Document, count: usize) -> Option<&Jump> { + todo!(); + } + + pub fn remove(&mut self, doc_id: &DocumentId) { + todo!(); + } + + pub fn iter(&self) -> impl DoubleEndedIterator { + self.marks.iter() + } + + /// Applies a [`Transaction`] of changes to the jumplist. + /// This is necessary to ensure that changes to documents do not leave jump-list + /// selections pointing to parts of the text which no longer exist. + fn apply(&mut self, transaction: &Transaction, doc: &Document) { + todo!(); + } +} #[derive(Debug, Clone)] pub struct JumpList { @@ -131,6 +177,7 @@ pub struct View { pub area: Rect, pub doc: DocumentId, pub jumps: JumpList, + pub marks: MarkList, // documents accessed from this view from the oldest one to last viewed one pub docs_access_history: Vec, /// the last modified files before the current one @@ -174,6 +221,7 @@ impl View { doc, area: Rect::default(), // will get calculated upon inserting into tree jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel + marks: MarkList::new((doc, Selection::point(0))), // TODO: use actual sel docs_access_history: Vec::new(), last_modified_docs: [None, None], object_selections: Vec::new(),