aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cursor.c
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2023-04-27 19:08:20 +0200
committerLuuk van Baal <luukvbaal@gmail.com>2023-05-02 13:11:47 +0200
commit26a9f0e94eb62047f0c2bb99401a8ac09840d0dd (patch)
tree87ba6d225ca418bf91092ee8735196a8cff4b7e1 /src/nvim/cursor.c
parent3621604029119a8806da006eb0468cf65e23b980 (diff)
downloadrneovim-26a9f0e94eb62047f0c2bb99401a8ac09840d0dd.tar.gz
rneovim-26a9f0e94eb62047f0c2bb99401a8ac09840d0dd.tar.bz2
rneovim-26a9f0e94eb62047f0c2bb99401a8ac09840d0dd.zip
vim-patch:9.0.0901: setting w_leftcol and handling side effects is confusing
Problem: Setting w_leftcol and handling side effects is confusing. Solution: Use a function to set w_leftcol() and handle side effects. https://github.com/vim/vim/commit/0c34d562647f029faca40f7733ccfb7b5377672b Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r--src/nvim/cursor.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index cdadc89e31..8ba0b2ffb3 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -439,23 +439,27 @@ void adjust_cursor_col(void)
}
}
-/// When curwin->w_leftcol has changed, adjust the cursor position.
+/// Set "curwin->w_leftcol" to "leftcol".
+/// Adjust the cursor position if needed.
///
/// @return true if the cursor was moved.
-bool leftcol_changed(void)
+bool set_leftcol(colnr_T leftcol)
{
- // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long.
- // Perhaps we can change p_siso to int.
- int64_t lastcol;
- colnr_T s, e;
- bool retval = false;
+ // Return quickly when there is no change.
+ if (curwin->w_leftcol == leftcol) {
+ return false;
+ }
+ curwin->w_leftcol = leftcol;
changed_cline_bef_curs();
- lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1;
+ // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long.
+ // Perhaps we can change p_siso to int.
+ int64_t lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1;
validate_virtcol();
+ bool retval = false;
// If the cursor is right or left of the screen, move it to last or first
- // character.
+ // visible character.
long siso = get_sidescrolloff_value(curwin);
if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) {
retval = true;
@@ -468,6 +472,7 @@ bool leftcol_changed(void)
// If the start of the character under the cursor is not on the screen,
// advance the cursor one more char. If this fails (last char of the
// line) adjust the scrolling.
+ colnr_T s, e;
getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e);
if (e > (colnr_T)lastcol) {
retval = true;