@@ -17,6 +17,8 @@ pub struct ParseResult<'buffer> {
17
17
pub marker : Option < & ' buffer str > ,
18
18
/// Direction of the search based on the marker
19
19
pub action : ParseAction ,
20
+ /// Prefix to search for
21
+ pub prefix : Option < & ' buffer str > ,
20
22
}
21
23
22
24
/// Direction of the index found in the string
@@ -30,6 +32,8 @@ pub enum ParseAction {
30
32
LastToken ,
31
33
/// Last executed command.
32
34
LastCommand ,
35
+ /// Backward search for a prefix
36
+ BackwardPrefixSearch ,
33
37
}
34
38
35
39
/// Splits a string that contains a marker character
@@ -46,7 +50,8 @@ pub enum ParseAction {
46
50
/// remainder: "this is an example",
47
51
/// index: Some(10),
48
52
/// marker: Some("!10"),
49
- /// action: ParseAction::ForwardSearch
53
+ /// action: ParseAction::ForwardSearch,
54
+ /// prefix: None,
50
55
/// }
51
56
/// )
52
57
///
@@ -58,6 +63,7 @@ pub fn parse_selection_char(buffer: &str, marker: char) -> ParseResult {
58
63
index : None ,
59
64
marker : None ,
60
65
action : ParseAction :: ForwardSearch ,
66
+ prefix : None ,
61
67
} ;
62
68
}
63
69
@@ -75,6 +81,7 @@ pub fn parse_selection_char(buffer: &str, marker: char) -> ParseResult {
75
81
index : Some ( 0 ) ,
76
82
marker : Some ( & buffer[ index..index + 2 * marker. len_utf8 ( ) ] ) ,
77
83
action : ParseAction :: LastCommand ,
84
+ prefix : None ,
78
85
}
79
86
}
80
87
#[ cfg( feature = "bashisms" ) ]
@@ -84,6 +91,7 @@ pub fn parse_selection_char(buffer: &str, marker: char) -> ParseResult {
84
91
index : Some ( 0 ) ,
85
92
marker : Some ( & buffer[ index..index + 2 ] ) ,
86
93
action : ParseAction :: LastToken ,
94
+ prefix : None ,
87
95
}
88
96
}
89
97
Some ( & x) if x. is_ascii_digit ( ) || x == '-' => {
@@ -106,6 +114,7 @@ pub fn parse_selection_char(buffer: &str, marker: char) -> ParseResult {
106
114
index : Some ( count) ,
107
115
marker : Some ( & buffer[ index..index + size] ) ,
108
116
action,
117
+ prefix : None ,
109
118
} ;
110
119
}
111
120
}
@@ -114,14 +123,26 @@ pub fn parse_selection_char(buffer: &str, marker: char) -> ParseResult {
114
123
index : Some ( count) ,
115
124
marker : Some ( & buffer[ index..index + size] ) ,
116
125
action,
126
+ prefix : None ,
117
127
} ;
118
128
}
129
+ #[ cfg( feature = "bashisms" ) ]
130
+ Some ( & x) if x. is_ascii_alphabetic ( ) => {
131
+ return ParseResult {
132
+ remainder : & buffer[ 0 ..index] ,
133
+ index : Some ( 0 ) ,
134
+ marker : Some ( & buffer[ index..index + marker. len_utf8 ( ) ] ) ,
135
+ action : ParseAction :: BackwardPrefixSearch ,
136
+ prefix : Some ( & buffer[ index + marker. len_utf8 ( ) ..buffer. len ( ) ] ) ,
137
+ }
138
+ }
119
139
None => {
120
140
return ParseResult {
121
141
remainder : & buffer[ 0 ..index] ,
122
142
index : Some ( 0 ) ,
123
143
marker : Some ( & buffer[ index..buffer. len ( ) ] ) ,
124
144
action,
145
+ prefix : Some ( & buffer[ index..buffer. len ( ) ] ) ,
125
146
}
126
147
}
127
148
_ => { }
@@ -135,6 +156,7 @@ pub fn parse_selection_char(buffer: &str, marker: char) -> ParseResult {
135
156
index : None ,
136
157
marker : None ,
137
158
action,
159
+ prefix : None ,
138
160
}
139
161
}
140
162
0 commit comments