aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2020-01-23 18:05:04 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2020-04-01 19:43:55 +0200
commit1fe0b329fe1d40e5837a43f53da0e0fff38477bc (patch)
tree4f4fe9af5166713bab5ac6403bf42636a6fdaa00 /src
parent4139678f97ee556ab142031a1ed5c7580278b64f (diff)
downloadrneovim-1fe0b329fe1d40e5837a43f53da0e0fff38477bc.tar.gz
rneovim-1fe0b329fe1d40e5837a43f53da0e0fff38477bc.tar.bz2
rneovim-1fe0b329fe1d40e5837a43f53da0e0fff38477bc.zip
api/ui: win_viewport event for visible range and cursor position in window
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/ui_events.in.h4
-rw-r--r--src/nvim/buffer_defs.h2
-rw-r--r--src/nvim/move.c9
-rw-r--r--src/nvim/normal.c1
-rw-r--r--src/nvim/screen.c5
-rw-r--r--src/nvim/ui.c2
-rw-r--r--src/nvim/window.c21
7 files changed, 40 insertions, 4 deletions
diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h
index 6677e248cf..ab31db39e9 100644
--- a/src/nvim/api/ui_events.in.h
+++ b/src/nvim/api/ui_events.in.h
@@ -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;
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 3993f61a3d..366766c292 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -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().
diff --git a/src/nvim/move.c b/src/nvim/move.c
index e7ed98d4f0..d4f82bc601 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -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;
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 6c92b136da..be131f7e00 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -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);
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 2e2c6ca737..6e1273ed0c 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -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
///
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 0f841760d6..3a5aa95ad3 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -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();
diff --git a/src/nvim/window.c b/src/nvim/window.c
index fb3f1e0c9f..9ec47f8e89 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -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);
+ }
}
}