@@ -1170,7 +1170,14 @@ fn split_selection_on_newline(cx: &mut Context) {
1170
1170
doc. set_selection ( view. id , selection) ;
1171
1171
}
1172
1172
1173
- fn search_impl ( doc : & mut Document , view : & mut View , contents : & str , regex : & Regex , extend : bool ) {
1173
+ fn search_impl (
1174
+ doc : & mut Document ,
1175
+ view : & mut View ,
1176
+ contents : & str ,
1177
+ regex : & Regex ,
1178
+ extend : bool ,
1179
+ scrolloff : usize ,
1180
+ ) {
1174
1181
let text = doc. text ( ) . slice ( ..) ;
1175
1182
let selection = doc. selection ( view. id ) ;
1176
1183
@@ -1205,7 +1212,11 @@ fn search_impl(doc: &mut Document, view: &mut View, contents: &str, regex: &Rege
1205
1212
} ;
1206
1213
1207
1214
doc. set_selection ( view. id , selection) ;
1208
- align_view ( doc, view, Align :: Center ) ;
1215
+ if view. is_cursor_in_view ( doc, 0 ) {
1216
+ view. ensure_cursor_in_view ( doc, scrolloff) ;
1217
+ } else {
1218
+ align_view ( doc, view, Align :: Center )
1219
+ }
1209
1220
} ;
1210
1221
}
1211
1222
@@ -1221,6 +1232,8 @@ fn search_completions(cx: &mut Context, reg: Option<char>) -> Vec<String> {
1221
1232
// TODO: use one function for search vs extend
1222
1233
fn search ( cx : & mut Context ) {
1223
1234
let reg = cx. register . unwrap_or ( '/' ) ;
1235
+ let scrolloff = cx. editor . config . scrolloff ;
1236
+
1224
1237
let ( _, doc) = current ! ( cx. editor) ;
1225
1238
1226
1239
// TODO: could probably share with select_on_matches?
@@ -1245,14 +1258,15 @@ fn search(cx: &mut Context) {
1245
1258
if event != PromptEvent :: Update {
1246
1259
return ;
1247
1260
}
1248
- search_impl ( doc, view, & contents, & regex, false ) ;
1261
+ search_impl ( doc, view, & contents, & regex, false , scrolloff ) ;
1249
1262
} ,
1250
1263
) ;
1251
1264
1252
1265
cx. push_layer ( Box :: new ( prompt) ) ;
1253
1266
}
1254
1267
1255
1268
fn search_next_impl ( cx : & mut Context , extend : bool ) {
1269
+ let scrolloff = cx. editor . config . scrolloff ;
1256
1270
let ( view, doc) = current ! ( cx. editor) ;
1257
1271
let registers = & cx. editor . registers ;
1258
1272
if let Some ( query) = registers. read ( '/' ) {
@@ -1267,7 +1281,7 @@ fn search_next_impl(cx: &mut Context, extend: bool) {
1267
1281
. case_insensitive ( case_insensitive)
1268
1282
. build ( )
1269
1283
{
1270
- search_impl ( doc, view, & contents, & regex, extend) ;
1284
+ search_impl ( doc, view, & contents, & regex, extend, scrolloff ) ;
1271
1285
} else {
1272
1286
// get around warning `mutable_borrow_reservation_conflict`
1273
1287
// which will be a hard error in the future
0 commit comments