Skip to content

Commit

Permalink
Change default for last_column in EditContext (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa authored Aug 10, 2024
1 parent 6fa08b6 commit e6412d5
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 67 deletions.
3 changes: 2 additions & 1 deletion crates/modalkit-ratatui/src/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ where
mod tests {
use super::*;
use modalkit::editing::store::Store;
use modalkit::env::vim::VimState;

macro_rules! mv {
($mt: expr) => {
Expand Down Expand Up @@ -1217,7 +1218,7 @@ mod tests {

fn mkboxstr(s: &str) -> (TextBoxState, EditContext, Store<EmptyInfo>) {
let (mut b, mut store) = mkbox();
let ctx = EditContext::default();
let ctx = EditContext::from(VimState::<EmptyInfo>::default());

b.set_text(s);
b.editor_command(&HistoryAction::Checkpoint.into(), &ctx, &mut store)
Expand Down
3 changes: 2 additions & 1 deletion crates/modalkit/src/editing/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ where
mod tests {
pub use super::*;
pub use crate::editing::application::EmptyInfo;
pub use crate::editing::context::EditContextBuilder;
pub use crate::editing::store::{RegisterCell, RegisterPutFlags, Store};
pub use crate::prelude::TargetShape::{BlockWise, CharWise, LineWise};

Expand All @@ -1426,7 +1427,7 @@ mod tests {
}

pub(super) fn mkctx() -> EditContext {
EditContext::default()
EditContextBuilder::default().last_column(false).build()
}

pub(super) fn mkbuf() -> EditBuffer<EmptyInfo> {
Expand Down
30 changes: 29 additions & 1 deletion crates/modalkit/src/editing/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Default for EditContext {
cursor_end: CursorEnd::Auto,
target_shape: None,
insert_style: None,
last_column: false,
last_column: true,
register: None,
register_append: false,
search_regex_dir: MoveDir1D::Next,
Expand Down Expand Up @@ -155,85 +155,113 @@ impl EditContextBuilder {
}

/// Set the [CursorEnd].
///
/// Defaults to [CursorEnd::Auto].
pub fn cursor_end(mut self, v: CursorEnd) -> Self {
self.0.cursor_end = v;
self
}

/// Set the [TargetShape].
///
/// Defaults to [None].
pub fn target_shape(mut self, v: Option<TargetShape>) -> Self {
self.0.target_shape = v;
self
}

/// Set the [InsertStyle].
///
/// Defaults to [None].
pub fn insert_style(mut self, v: Option<InsertStyle>) -> Self {
self.0.insert_style = v;
self
}

/// Set whether it's okay to move the cursor into the last column.
///
/// Defaults to [true].
pub fn last_column(mut self, v: bool) -> Self {
self.0.last_column = v;
self
}

/// Set the [Register].
///
/// Defaults to [None].
pub fn register(mut self, v: Option<Register>) -> Self {
self.0.register = v;
self
}

/// Set whether this operation should append contents to the register or replace the existing
/// ones.
///
/// Defaults to [false].
pub fn register_append(mut self, v: bool) -> Self {
self.0.register_append = v;
self
}

/// Set the direction the regular expression should search in.
///
/// Defaults to [MoveDir1D::Next].
pub fn search_regex_dir(mut self, v: MoveDir1D) -> Self {
self.0.search_regex_dir = v;
self
}

/// Set a character to search for.
///
/// Defaults to [None].
pub fn search_char(mut self, v: Option<(MoveDir1D, bool, Char)>) -> Self {
self.0.search_char = v;
self
}

/// Set a [Char] to replace existing characters with.
///
/// Defaults to [None].
pub fn replace_char(mut self, v: Option<Char>) -> Self {
self.0.replace_char = v;
self
}

/// Set whether we should do an incremental search.
///
/// Defaults to [false].
pub fn search_incremental(mut self, v: bool) -> Self {
self.0.search_incremental = v;
self
}

/// Set the contextual [Mark].
///
/// Defaults to [None].
pub fn mark(mut self, mark: Option<Mark>) -> Self {
self.0.mark = mark;
self
}

/// Set the contextual [Mark].
///
/// Defaults to [None].
pub fn typed_char(mut self, ch: Option<Char>) -> Self {
self.0.typed = ch;
self
}

/// Set the contextual [Mark].
///
/// Defaults to [EditAction::Motion].
pub fn operation(mut self, op: EditAction) -> Self {
self.0.operation = op;
self
}

/// Set the contextual count.
///
/// Defaults to [None].
pub fn count(mut self, n: Option<usize>) -> Self {
self.0.count = n;
self
Expand Down
2 changes: 1 addition & 1 deletion crates/modalkit/src/editing/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ mod tests {
#[test]
fn test_macro_run() {
let (mut bindings, mut store) = setup_bindings(true);
let ctx = EditContext::default();
let ctx = EditContext::from(VimState::<EmptyInfo>::default());

// Run a sequence of key presses twice.
let run = MacroAction::Run("flif<Esc>fi".into(), 2.into());
Expand Down
Loading

0 comments on commit e6412d5

Please sign in to comment.