Skip to content

Commit ef7b96c

Browse files
authored
Revert "Fix move to line start in multi-line history entries" (#704)
1 parent 0c5f981 commit ef7b96c

File tree

1 file changed

+13
-106
lines changed

1 file changed

+13
-106
lines changed

src/engine.rs

Lines changed: 13 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,15 @@ impl Reedline {
14031403
/// Executes [`EditCommand`] actions by modifying the internal state appropriately. Does not output itself.
14041404
pub fn run_edit_commands(&mut self, commands: &[EditCommand]) {
14051405
if self.input_mode == InputMode::HistoryTraversal {
1406+
if matches!(
1407+
self.history_cursor.get_navigation(),
1408+
HistoryNavigationQuery::Normal(_)
1409+
) {
1410+
if let Some(string) = self.history_cursor.string_at_cursor() {
1411+
self.editor
1412+
.set_buffer(string, UndoBehavior::HistoryNavigation);
1413+
}
1414+
}
14061415
self.input_mode = InputMode::Regular;
14071416
}
14081417

@@ -1757,110 +1766,8 @@ impl Reedline {
17571766
}
17581767
}
17591768

1760-
#[cfg(test)]
1761-
mod test {
1762-
use super::*;
1763-
use crate::DefaultPrompt;
1764-
use pretty_assertions::assert_eq;
1765-
use rstest::rstest;
1766-
use std::error::Error;
1767-
use std::result::Result;
1768-
1769-
#[test]
1770-
fn thread_safe() {
1771-
fn f<S: Send>(_: S) {}
1772-
f(Reedline::create());
1773-
}
1774-
1775-
#[rstest]
1776-
#[case("")]
1777-
#[case("line of text")]
1778-
#[case(
1779-
"longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line of text"
1780-
)]
1781-
fn test_move_to_line_start(#[case] input: &str) -> Result<(), Box<dyn Error>> {
1782-
let mut reedline = Reedline::create();
1783-
let prompt = DefaultPrompt::default();
1784-
1785-
let insert_input_event =
1786-
ReedlineEvent::Edit(vec![EditCommand::InsertString(input.to_string())]);
1787-
let move_to_line_start_event = ReedlineEvent::Edit(vec![EditCommand::MoveToLineStart]);
1788-
1789-
// Have to resize, or painting.utils.estimate_single_line_wraps panics with divide-by-zero.
1790-
reedline.handle_event(&prompt, ReedlineEvent::Resize(u16::MAX, u16::MAX))?;
1791-
1792-
// Write the string, and then move to the start of the line.
1793-
reedline.handle_event(&prompt, insert_input_event)?;
1794-
reedline.handle_event(&prompt, move_to_line_start_event.clone())?;
1795-
assert_eq!(reedline.editor.line_buffer().insertion_point(), 0);
1796-
1797-
// Enter the string into history, then scroll back up and move to the start of the line.
1798-
reedline.handle_event(&prompt, ReedlineEvent::Enter)?;
1799-
reedline.handle_event(&prompt, ReedlineEvent::Up)?;
1800-
reedline.handle_event(&prompt, move_to_line_start_event)?;
1801-
assert_eq!(reedline.editor.line_buffer().insertion_point(), 0);
1802-
1803-
Ok(())
1804-
}
1805-
1806-
#[rstest]
1807-
// Each input must be >=2 lines.
1808-
// Up/Down commands move in text/history depending on the number of lines.
1809-
#[case("a\nb", 2, 2)]
1810-
#[case("123456789\n123456789\n123456789", 10, 20)]
1811-
#[case("0\n1\n2\n3\n4\n5\n6\n7\n8\n9", 2, 18)]
1812-
fn test_move_to_line_start_multiline(
1813-
#[case] input: &str,
1814-
#[case] second_line_start: usize,
1815-
#[case] last_line_start: usize,
1816-
) -> Result<(), Box<dyn Error>> {
1817-
let mut reedline = Reedline::create();
1818-
let prompt = DefaultPrompt::default();
1819-
1820-
let insert_input_event =
1821-
ReedlineEvent::Edit(vec![EditCommand::InsertString(input.to_string())]);
1822-
let move_to_line_start_event = ReedlineEvent::Edit(vec![EditCommand::MoveToLineStart]);
1823-
let move_to_end_event = ReedlineEvent::Edit(vec![EditCommand::MoveToEnd]);
1824-
1825-
// Have to resize, or painting.utils.estimate_single_line_wraps panics with divide-by-zero.
1826-
reedline.handle_event(&prompt, ReedlineEvent::Resize(u16::MAX, u16::MAX))?;
1827-
1828-
// Write the string, and then move to the start of the last line.
1829-
reedline.handle_event(&prompt, insert_input_event)?;
1830-
reedline.handle_event(&prompt, move_to_line_start_event.clone())?;
1831-
assert_eq!(
1832-
reedline.editor.line_buffer().insertion_point(),
1833-
last_line_start
1834-
);
1835-
1836-
// Enter the string into history, then scroll back up and move to the start of the first line.
1837-
reedline.handle_event(&prompt, ReedlineEvent::Enter)?;
1838-
reedline.handle_event(&prompt, ReedlineEvent::Up)?;
1839-
reedline.handle_event(&prompt, move_to_line_start_event.clone())?;
1840-
assert_eq!(reedline.editor.line_buffer().insertion_point(), 0);
1841-
1842-
// Enter the string again, then scroll up in history, move down one line,
1843-
// and move to the start of the second line.
1844-
reedline.handle_event(&prompt, ReedlineEvent::Enter)?;
1845-
reedline.handle_event(&prompt, ReedlineEvent::Up)?;
1846-
reedline.handle_event(&prompt, ReedlineEvent::Down)?;
1847-
reedline.handle_event(&prompt, move_to_line_start_event.clone())?;
1848-
assert_eq!(
1849-
reedline.editor.line_buffer().insertion_point(),
1850-
second_line_start
1851-
);
1852-
1853-
// Enter the string again, then scroll up in history, move to the end of the text,
1854-
// and move to the start of the last line.
1855-
reedline.handle_event(&prompt, ReedlineEvent::Enter)?;
1856-
reedline.handle_event(&prompt, ReedlineEvent::Up)?;
1857-
reedline.handle_event(&prompt, move_to_end_event)?;
1858-
reedline.handle_event(&prompt, move_to_line_start_event)?;
1859-
assert_eq!(
1860-
reedline.editor.line_buffer().insertion_point(),
1861-
last_line_start
1862-
);
1863-
1864-
Ok(())
1865-
}
1769+
#[test]
1770+
fn thread_safe() {
1771+
fn f<S: Send>(_: S) {}
1772+
f(Reedline::create());
18661773
}

0 commit comments

Comments
 (0)