Skip to content

Commit

Permalink
Use reset pattern for all modes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Apr 8, 2024
1 parent 18ad6ae commit 2335e6b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/commands/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn switch_to_line_jump_mode(app: &mut Application) -> Result {
if app.workspace.current_buffer.is_some() {
app.switch_to(ModeKey::LineJump);
if let Mode::LineJump(ref mut mode) = app.mode {
mode.input = String::new()
mode.reset();
}
} else {
bail!(BUFFER_MISSING);
Expand Down Expand Up @@ -163,7 +163,7 @@ pub fn switch_to_select_mode(app: &mut Application) -> Result {

app.switch_to(ModeKey::Select);
if let Mode::Select(ref mut mode) = app.mode {
mode.anchor = position
mode.reset(position);
}

Ok(())
Expand All @@ -180,7 +180,7 @@ pub fn switch_to_select_line_mode(app: &mut Application) -> Result {

app.switch_to(ModeKey::SelectLine);
if let Mode::SelectLine(ref mut mode) = app.mode {
mode.anchor = line
mode.reset(line);
}

Ok(())
Expand All @@ -190,7 +190,7 @@ pub fn switch_to_search_mode(app: &mut Application) -> Result {
if app.workspace.current_buffer.is_some() {
app.switch_to(ModeKey::Search);
if let Mode::Search(ref mut mode) = app.mode {
mode.insert = true
mode.reset();
}
} else {
bail!(BUFFER_MISSING);
Expand Down
4 changes: 4 additions & 0 deletions src/models/application/modes/line_jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ impl LineJumpMode {
pub fn new() -> LineJumpMode {
LineJumpMode::default()
}

pub fn reset(&mut self) {
self.input = String::new();
}
}
4 changes: 4 additions & 0 deletions src/models/application/modes/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl SearchMode {
}
}

pub fn reset(&mut self) {
self.insert = true;
}

pub fn insert_mode(&self) -> bool {
self.insert
}
Expand Down
4 changes: 4 additions & 0 deletions src/models/application/modes/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ impl SelectMode {
pub fn new(anchor: Position) -> SelectMode {
SelectMode { anchor }
}

pub fn reset(&mut self, anchor: Position) {
self.anchor = anchor;
}
}
4 changes: 4 additions & 0 deletions src/models/application/modes/select_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ impl SelectLineMode {
SelectLineMode { anchor }
}

pub fn reset(&mut self, anchor: usize) {
self.anchor = anchor;
}

pub fn to_range(&self, cursor: &Position) -> Range {
LineRange::new(self.anchor, cursor.line).to_inclusive_range()
}
Expand Down

0 comments on commit 2335e6b

Please sign in to comment.