api/ui: win_viewport event for visible range and cursor position in window

This commit is contained in:
Björn Linse
2020-01-23 18:05:04 +01:00
parent 4139678f97
commit 1fe0b329fe
11 changed files with 305 additions and 21 deletions

View File

@@ -115,6 +115,10 @@ void win_close(Integer grid)
void msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep_char)
FUNC_API_SINCE(6) FUNC_API_BRIDGE_IMPL FUNC_API_COMPOSITOR_IMPL;
void win_viewport(Integer grid, Window win, Integer topline,
Integer botline, Integer curline, Integer curcol)
FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY;
void popupmenu_show(Array items, Integer selected,
Integer row, Integer col, Integer grid)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;

View File

@@ -1190,6 +1190,8 @@ struct window_S {
to adjust w_valid */
colnr_T w_valid_leftcol; /* last known w_leftcol */
bool w_viewport_invalid;
/*
* w_cline_height is the number of physical lines taken by the buffer line
* that the cursor is on. We use this to avoid extra calls to plines().

View File

@@ -86,6 +86,7 @@ static void comp_botline(win_T *wp)
/* wp->w_botline is the line that is just below the window */
wp->w_botline = lnum;
wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
wp->w_viewport_invalid = true;
set_empty_rows(wp, done);
@@ -151,6 +152,7 @@ void update_topline(void)
curwin->w_topline = curwin->w_cursor.lnum;
curwin->w_botline = curwin->w_topline;
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
curwin->w_viewport_invalid = true;
curwin->w_scbind_pos = 1;
return;
}
@@ -175,6 +177,7 @@ void update_topline(void)
curwin->w_topline = 1;
curwin->w_botline = 2;
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
curwin->w_viewport_invalid = true;
curwin->w_scbind_pos = 1;
}
/*
@@ -311,6 +314,7 @@ void update_topline(void)
}
}
curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true;
win_check_anchored_floats(curwin);
/*
@@ -407,6 +411,7 @@ void check_cursor_moved(win_T *wp)
|VALID_CHEIGHT|VALID_CROW|VALID_TOPLINE);
wp->w_valid_cursor = wp->w_cursor;
wp->w_valid_leftcol = wp->w_leftcol;
wp->w_viewport_invalid = true;
} else if (wp->w_cursor.col != wp->w_valid_cursor.col
|| wp->w_leftcol != wp->w_valid_leftcol
|| wp->w_cursor.coladd != wp->w_valid_cursor.coladd
@@ -415,6 +420,7 @@ void check_cursor_moved(win_T *wp)
wp->w_valid_cursor.col = wp->w_cursor.col;
wp->w_valid_leftcol = wp->w_leftcol;
wp->w_valid_cursor.coladd = wp->w_cursor.coladd;
wp->w_viewport_invalid = true;
}
}
@@ -1458,6 +1464,7 @@ void scroll_cursor_top(int min_scroll, int always)
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true;
}
}
@@ -1662,6 +1669,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
curwin->w_valid = old_valid;
}
curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true;
}
/// Recompute topline to put the cursor halfway across the window
@@ -1818,6 +1826,7 @@ void cursor_correct(void)
}
}
curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true;
}

View File

@@ -4121,6 +4121,7 @@ void scroll_redraw(int up, long count)
}
if (curwin->w_cursor.lnum != prev_lnum)
coladvance(curwin->w_curswant);
curwin->w_viewport_invalid = true;
redraw_later(VALID);
}

View File

@@ -417,7 +417,7 @@ int update_screen(int type)
need_wait_return = false;
}
win_ui_flush_positions();
win_ui_flush();
msg_ext_check_clear();
/* reset cmdline_row now (may have been changed temporarily) */
@@ -1629,6 +1629,7 @@ static void win_update(win_T *wp)
* changes are relevant).
*/
wp->w_valid |= VALID_BOTLINE;
wp->w_viewport_invalid = true;
if (wp == curwin && wp->w_botline != old_botline && !recursive) {
recursive = TRUE;
curwin->w_valid &= ~VALID_TOPLINE;
@@ -1648,7 +1649,7 @@ static void win_update(win_T *wp)
/* restore got_int, unless CTRL-C was hit while redrawing */
if (!got_int)
got_int = save_got_int;
}
} // NOLINT(readability/fn_size)
/// Returns width of the signcolumn that should be used for the whole window
///

View File

@@ -424,7 +424,7 @@ int ui_current_col(void)
void ui_flush(void)
{
cmdline_ui_flush();
win_ui_flush_positions();
win_ui_flush();
msg_ext_ui_flush();
msg_scroll_flush();

View File

@@ -773,6 +773,21 @@ static void ui_ext_win_position(win_T *wp)
}
void ui_ext_win_viewport(win_T *wp)
{
if ((wp == curwin || ui_has(kUIMultigrid)) && wp->w_viewport_invalid) {
int botline = wp->w_botline;
if (botline == wp->w_buffer->b_ml.ml_line_count+1
&& wp->w_empty_rows == 0) {
// TODO(bfredl): The might be more cases to consider, like how does this
// interact with incomplete final line? Diff filler lines?
botline = wp->w_buffer->b_ml.ml_line_count;
}
ui_call_win_viewport(wp->w_grid.handle, wp->handle, wp->w_topline-1,
botline, wp->w_cursor.lnum-1, wp->w_cursor.col);
wp->w_viewport_invalid = false;
}
}
static bool parse_float_anchor(String anchor, FloatAnchor *out)
{
@@ -4688,6 +4703,7 @@ static win_T *win_alloc(win_T *after, int hidden)
new_wp->w_scbind_pos = 1;
new_wp->w_floating = 0;
new_wp->w_float_config = FLOAT_CONFIG_INIT;
new_wp->w_viewport_invalid = true;
// use global option for global-local options
new_wp->w_p_so = -1;
@@ -6992,7 +7008,7 @@ void get_framelayout(const frame_T *fr, list_T *l, bool outer)
}
}
void win_ui_flush_positions(void)
void win_ui_flush(void)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_pos_changed && wp->w_grid.chars != NULL) {
@@ -7003,6 +7019,9 @@ void win_ui_flush_positions(void)
}
wp->w_pos_changed = false;
}
if (tp == curtab) {
ui_ext_win_viewport(wp);
}
}
}