mirror of
https://github.com/neovim/neovim.git
synced 2025-10-13 21:36:05 +00:00
fix(cmdline): set search cursor after ui_flush() (#34418)
Problem: vim.ui_attach cmdline events emitted with an ephemeral cursor position that is only used as the start of the search. Solution: Delay setting the cursor position until after ui_flush().
This commit is contained in:
@@ -421,7 +421,6 @@ theend:
|
|||||||
// May do 'incsearch' highlighting if desired.
|
// May do 'incsearch' highlighting if desired.
|
||||||
static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state_T *s)
|
static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state_T *s)
|
||||||
{
|
{
|
||||||
pos_T end_pos;
|
|
||||||
int skiplen, patlen;
|
int skiplen, patlen;
|
||||||
int search_delim;
|
int search_delim;
|
||||||
|
|
||||||
@@ -429,8 +428,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
|
|||||||
// NOTE: must call restore_last_search_pattern() before returning!
|
// NOTE: must call restore_last_search_pattern() before returning!
|
||||||
save_last_search_pattern();
|
save_last_search_pattern();
|
||||||
|
|
||||||
if (!do_incsearch_highlighting(firstc, &search_delim, s, &skiplen,
|
if (!do_incsearch_highlighting(firstc, &search_delim, s, &skiplen, &patlen)) {
|
||||||
&patlen)) {
|
|
||||||
restore_last_search_pattern();
|
restore_last_search_pattern();
|
||||||
finish_incsearch_highlighting(false, s, true);
|
finish_incsearch_highlighting(false, s, true);
|
||||||
return;
|
return;
|
||||||
@@ -444,6 +442,16 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
|
|||||||
}
|
}
|
||||||
s->incsearch_postponed = false;
|
s->incsearch_postponed = false;
|
||||||
|
|
||||||
|
// Use the previous pattern for ":s//".
|
||||||
|
char next_char = ccline.cmdbuff[skiplen + patlen];
|
||||||
|
bool use_last_pat = patlen == 0 && skiplen > 0
|
||||||
|
&& ccline.cmdbuff[skiplen - 1] == next_char;
|
||||||
|
|
||||||
|
if (patlen != 0 || use_last_pat) {
|
||||||
|
ui_busy_start();
|
||||||
|
ui_flush();
|
||||||
|
}
|
||||||
|
|
||||||
if (search_first_line == 0) {
|
if (search_first_line == 0) {
|
||||||
// start at the original cursor position
|
// start at the original cursor position
|
||||||
curwin->w_cursor = s->search_start;
|
curwin->w_cursor = s->search_start;
|
||||||
@@ -456,40 +464,27 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
|
|||||||
curwin->w_cursor.lnum = search_first_line;
|
curwin->w_cursor.lnum = search_first_line;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
}
|
}
|
||||||
int found; // do_search() result
|
|
||||||
|
|
||||||
// Use the previous pattern for ":s//".
|
int found = 0; // do_search() result
|
||||||
char next_char = ccline.cmdbuff[skiplen + patlen];
|
|
||||||
bool use_last_pat = patlen == 0 && skiplen > 0
|
|
||||||
&& ccline.cmdbuff[skiplen - 1] == next_char;
|
|
||||||
|
|
||||||
// If there is no pattern, don't do anything.
|
if (patlen != 0 || use_last_pat) {
|
||||||
if (patlen == 0 && !use_last_pat) {
|
|
||||||
found = 0;
|
|
||||||
set_no_hlsearch(true); // turn off previous highlight
|
|
||||||
redraw_all_later(UPD_SOME_VALID);
|
|
||||||
} else {
|
|
||||||
int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK;
|
int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK;
|
||||||
ui_busy_start();
|
|
||||||
ui_flush();
|
|
||||||
emsg_off++; // So it doesn't beep if bad expr
|
|
||||||
// Set the time limit to half a second.
|
|
||||||
proftime_T tm = profile_setlimit(500);
|
|
||||||
if (!p_hls) {
|
if (!p_hls) {
|
||||||
search_flags += SEARCH_KEEP;
|
search_flags += SEARCH_KEEP;
|
||||||
}
|
}
|
||||||
if (search_first_line != 0) {
|
if (search_first_line != 0) {
|
||||||
search_flags += SEARCH_START;
|
search_flags += SEARCH_START;
|
||||||
}
|
}
|
||||||
|
// Set the time limit to half a second.
|
||||||
|
proftime_T tm = profile_setlimit(500);
|
||||||
|
searchit_arg_T sia = { .sa_tm = &tm };
|
||||||
ccline.cmdbuff[skiplen + patlen] = NUL;
|
ccline.cmdbuff[skiplen + patlen] = NUL;
|
||||||
searchit_arg_T sia = {
|
emsg_off++; // So it doesn't beep if bad expr
|
||||||
.sa_tm = &tm,
|
|
||||||
};
|
|
||||||
found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
|
found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
|
||||||
ccline.cmdbuff + skiplen, (size_t)patlen, count,
|
ccline.cmdbuff + skiplen, (size_t)patlen, count,
|
||||||
search_flags, &sia);
|
search_flags, &sia);
|
||||||
ccline.cmdbuff[skiplen + patlen] = next_char;
|
|
||||||
emsg_off--;
|
emsg_off--;
|
||||||
|
ccline.cmdbuff[skiplen + patlen] = next_char;
|
||||||
if (curwin->w_cursor.lnum < search_first_line
|
if (curwin->w_cursor.lnum < search_first_line
|
||||||
|| curwin->w_cursor.lnum > search_last_line) {
|
|| curwin->w_cursor.lnum > search_last_line) {
|
||||||
// match outside of address range
|
// match outside of address range
|
||||||
@@ -507,13 +502,12 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
|
|||||||
s->incsearch_postponed = true;
|
s->incsearch_postponed = true;
|
||||||
}
|
}
|
||||||
ui_busy_stop();
|
ui_busy_stop();
|
||||||
|
} else {
|
||||||
|
set_no_hlsearch(true); // turn off previous highlight
|
||||||
|
redraw_all_later(UPD_SOME_VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found != 0) {
|
highlight_match = found != 0; // add or remove search match position
|
||||||
highlight_match = true; // highlight position
|
|
||||||
} else {
|
|
||||||
highlight_match = false; // remove highlight
|
|
||||||
}
|
|
||||||
|
|
||||||
// first restore the old curwin values, so the screen is
|
// first restore the old curwin values, so the screen is
|
||||||
// positioned in the same way as the actual search command
|
// positioned in the same way as the actual search command
|
||||||
@@ -521,17 +515,14 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
|
|||||||
changed_cline_bef_curs(curwin);
|
changed_cline_bef_curs(curwin);
|
||||||
update_topline(curwin);
|
update_topline(curwin);
|
||||||
|
|
||||||
|
pos_T end_pos = curwin->w_cursor;
|
||||||
if (found != 0) {
|
if (found != 0) {
|
||||||
pos_T save_pos = curwin->w_cursor;
|
|
||||||
|
|
||||||
s->match_start = curwin->w_cursor;
|
s->match_start = curwin->w_cursor;
|
||||||
set_search_match(&curwin->w_cursor);
|
set_search_match(&curwin->w_cursor);
|
||||||
validate_cursor(curwin);
|
validate_cursor(curwin);
|
||||||
end_pos = curwin->w_cursor;
|
s->match_end = curwin->w_cursor;
|
||||||
s->match_end = end_pos;
|
curwin->w_cursor = end_pos;
|
||||||
curwin->w_cursor = save_pos;
|
end_pos = s->match_end;
|
||||||
} else {
|
|
||||||
end_pos = curwin->w_cursor; // shutup gcc 4
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable 'hlsearch' highlighting if the pattern matches
|
// Disable 'hlsearch' highlighting if the pattern matches
|
||||||
|
Reference in New Issue
Block a user