Cursor now moved to end of the line while scrolling history, original position in pending command still remembered -m Undo now moves the cursor to it's original position in normal mode
This commit is contained in:
@@ -271,13 +271,18 @@ impl History {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_pending_cmd(&mut self, buf: (&str, usize)) {
|
pub fn update_pending_cmd(&mut self, buf: (&str, usize)) {
|
||||||
|
let cursor_pos = if let Some(pending) = &self.pending {
|
||||||
|
pending.1
|
||||||
|
} else {
|
||||||
|
buf.1
|
||||||
|
};
|
||||||
let cmd = buf.0.to_string();
|
let cmd = buf.0.to_string();
|
||||||
let constraint = SearchConstraint {
|
let constraint = SearchConstraint {
|
||||||
kind: SearchKind::Prefix,
|
kind: SearchKind::Prefix,
|
||||||
term: cmd.clone(),
|
term: cmd.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.pending = Some((cmd, buf.1));
|
self.pending = Some((cmd, cursor_pos));
|
||||||
self.constrain_entries(constraint);
|
self.constrain_entries(constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,12 @@ impl LineBuf {
|
|||||||
pub fn set_cursor_clamp(&mut self, yn: bool) {
|
pub fn set_cursor_clamp(&mut self, yn: bool) {
|
||||||
self.cursor.exclusive = yn;
|
self.cursor.exclusive = yn;
|
||||||
}
|
}
|
||||||
|
pub fn move_cursor_to_end(&mut self) {
|
||||||
|
self.move_cursor(MotionKind::To(self.grapheme_indices().len()))
|
||||||
|
}
|
||||||
|
pub fn move_cursor_to_start(&mut self) {
|
||||||
|
self.move_cursor(MotionKind::To(0))
|
||||||
|
}
|
||||||
pub fn cursor_byte_pos(&mut self) -> usize {
|
pub fn cursor_byte_pos(&mut self) -> usize {
|
||||||
self.index_byte_pos(self.cursor.get())
|
self.index_byte_pos(self.cursor.get())
|
||||||
}
|
}
|
||||||
@@ -2555,11 +2561,8 @@ impl LineBuf {
|
|||||||
|
|
||||||
self.buffer.replace_range(pos..pos + new.len(), &old);
|
self.buffer.replace_range(pos..pos + new.len(), &old);
|
||||||
let new_cursor_pos = self.cursor.get();
|
let new_cursor_pos = self.cursor.get();
|
||||||
let in_insert_mode = !self.cursor.exclusive;
|
|
||||||
|
|
||||||
if in_insert_mode {
|
self.cursor.set(cursor_pos);
|
||||||
self.cursor.set(cursor_pos)
|
|
||||||
}
|
|
||||||
let new_edit = Edit {
|
let new_edit = Edit {
|
||||||
pos,
|
pos,
|
||||||
cursor_pos: new_cursor_pos,
|
cursor_pos: new_cursor_pos,
|
||||||
|
|||||||
@@ -316,15 +316,17 @@ impl FernVi {
|
|||||||
let entry = self.history.scroll(count);
|
let entry = self.history.scroll(count);
|
||||||
log::info!("Scrolled history, got entry: {:?}", entry.as_ref());
|
log::info!("Scrolled history, got entry: {:?}", entry.as_ref());
|
||||||
if let Some(entry) = entry {
|
if let Some(entry) = entry {
|
||||||
log::info!("Setting buffer to history entry: {}", entry.command());
|
let cursor_pos = self.editor.cursor.get();
|
||||||
|
log::info!("Saving pending command to history: {:?} at cursor pos {}", self.editor.as_str(), cursor_pos);
|
||||||
let pending = self.editor.take_buf();
|
let pending = self.editor.take_buf();
|
||||||
self.editor.set_buffer(entry.command().to_string());
|
self.editor.set_buffer(entry.command().to_string());
|
||||||
if self.history.pending.is_none() {
|
if self.history.pending.is_none() {
|
||||||
self.history.pending = Some((pending, self.editor.cursor.get()));
|
self.history.pending = Some((pending, cursor_pos));
|
||||||
}
|
}
|
||||||
self.editor.set_hint(None);
|
self.editor.set_hint(None);
|
||||||
|
self.editor.move_cursor_to_end();
|
||||||
} else if let Some(pending) = self.history.pending.take() {
|
} else if let Some(pending) = self.history.pending.take() {
|
||||||
log::info!("Setting buffer to pending command: {}", &pending.0);
|
log::info!("Setting buffer to pending command: {:?}", &pending);
|
||||||
self.editor.set_buffer(pending.0);
|
self.editor.set_buffer(pending.0);
|
||||||
self.editor.cursor.set(pending.1);
|
self.editor.cursor.set(pending.1);
|
||||||
self.editor.set_hint(None);
|
self.editor.set_hint(None);
|
||||||
|
|||||||
Reference in New Issue
Block a user