@@ -522,14 +522,18 @@ textinput_curses::handle_search_key(const ncinput& ch)
522522 }
523523 case ' s' :
524524 case ' S' : {
525- this ->tc_search_start_point = this ->tc_cursor ;
526- this ->move_cursor_to_next_search_hit ();
525+ if (!this ->tc_search .empty ()) {
526+ this ->tc_search_start_point = this ->tc_cursor ;
527+ this ->move_cursor_to_next_search_hit ();
528+ }
527529 return true ;
528530 }
529531 case ' r' :
530532 case ' R' : {
531- this ->tc_search_start_point = this ->tc_cursor ;
532- this ->move_cursor_to_prev_search_hit ();
533+ if (!this ->tc_search .empty ()) {
534+ this ->tc_search_start_point = this ->tc_cursor ;
535+ this ->move_cursor_to_prev_search_hit ();
536+ }
533537 return true ;
534538 }
535539 }
@@ -606,6 +610,10 @@ textinput_curses::handle_search_key(const ncinput& ch)
606610void
607611textinput_curses::move_cursor_to_next_search_hit ()
608612{
613+ if (this ->tc_search_code == nullptr ) {
614+ return ;
615+ }
616+
609617 auto x = this ->tc_search_start_point .x ;
610618 if (this ->tc_search_found && !this ->tc_search_found .value ()) {
611619 this ->tc_search_start_point .y = 0 ;
@@ -796,6 +804,8 @@ textinput_curses::handle_key(const ncinput& ch)
796804{
797805 static const auto PREFIX_RE = lnav::pcre2pp::code::from_const (
798806 R"( ^\s*((?:-|\*|1\.|>)(?:\s+\[( |x|X)\])?\s*))" );
807+ static const auto PREFIX_OR_WS_RE = lnav::pcre2pp::code::from_const (
808+ R"( ^\s*((?:-|\*|1\.|>)?(?:\s+\[( |x|X)\])?\s+))" );
799809 thread_local auto md = lnav::pcre2pp::match_data::unitialized ();
800810
801811 if (this ->tc_notice ) {
@@ -1175,11 +1185,12 @@ textinput_curses::handle_key(const ncinput& ch)
11751185 auto indent = std::string (" \n " );
11761186 if (!this ->tc_selection ) {
11771187 log_debug (" checking for prefix" );
1178- auto match_opt = PREFIX_RE .capture_from (al_sf)
1188+ auto match_opt = PREFIX_OR_WS_RE .capture_from (al_sf)
11791189 .into (md)
11801190 .matches ()
11811191 .ignore_error ();
11821192 if (match_opt) {
1193+ log_debug (" has prefix" );
11831194 this ->tc_selection = selected_range::from_key (
11841195 this ->tc_cursor .copy_with_x (
11851196 prefix_sf.column_width ()),
@@ -1195,13 +1206,18 @@ textinput_curses::handle_key(const ncinput& ch)
11951206 if (!is_comment && !al.empty ()
11961207 && match_opt->f_all .length () == al.length ())
11971208 {
1209+ log_debug (" clear left" );
11981210 this ->command_indent (indent_mode_t ::clear_left);
1199- } else {
1211+ } else if ( this -> is_cursor_at_end_of_line ()) {
12001212 indent.append (match_opt->f_all .data (),
12011213 match_opt->f_all .length ());
12021214 if (md[2 ] && md[2 ]->front () != ' ' ) {
12031215 indent[1 + md[2 ]->sf_begin ] = ' ' ;
12041216 }
1217+ } else {
1218+ indent.append (match_opt->f_all .length (), ' ' );
1219+ this ->tc_selection
1220+ = selected_range::from_point (this ->tc_cursor );
12051221 }
12061222 } else {
12071223 this ->tc_selection
@@ -1289,7 +1305,8 @@ textinput_curses::handle_key(const ncinput& ch)
12891305 .ignore_error ();
12901306
12911307 if (match_opt && !match_opt->f_all .empty ()
1292- && match_opt->f_all .sf_end == this ->tc_cursor .x ) {
1308+ && match_opt->f_all .sf_end == this ->tc_cursor .x )
1309+ {
12931310 auto is_comment = al.al_attrs
12941311 | lnav::itertools::find_if ([](const string_attr& sa) {
12951312 return (sa.sa_type == &VC_ROLE)
@@ -1311,12 +1328,8 @@ textinput_curses::handle_key(const ncinput& ch)
13111328 this ->tc_doc_meta .m_indents .end (),
13121329 this ->tc_cursor .x );
13131330 if (indent_iter != this ->tc_doc_meta .m_indents .end ()) {
1314- if (indent_iter = = this ->tc_doc_meta .m_indents .begin ())
1331+ if (indent_iter ! = this ->tc_doc_meta .m_indents .begin ())
13151332 {
1316- this ->tc_selection = selected_range::from_key (
1317- this ->tc_cursor .copy_with_x (0 ),
1318- this ->tc_cursor );
1319- } else {
13201333 auto prev_indent_iter = std::prev (indent_iter);
13211334 this ->tc_selection = selected_range::from_key (
13221335 this ->tc_cursor .copy_with_x (*prev_indent_iter),
0 commit comments