@@ -1403,6 +1403,15 @@ impl Reedline {
1403
1403
/// Executes [`EditCommand`] actions by modifying the internal state appropriately. Does not output itself.
1404
1404
pub fn run_edit_commands ( & mut self , commands : & [ EditCommand ] ) {
1405
1405
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
+ }
1406
1415
self . input_mode = InputMode :: Regular ;
1407
1416
}
1408
1417
@@ -1757,110 +1766,8 @@ impl Reedline {
1757
1766
}
1758
1767
}
1759
1768
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\n b" , 2 , 2 ) ]
1810
- #[ case( "123456789\n 123456789\n 123456789" , 10 , 20 ) ]
1811
- #[ case( "0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9" , 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 ( ) ) ;
1866
1773
}
0 commit comments