diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-08-28 11:35:09 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-08-29 09:26:15 +0200 |
commit | 0a81ec14a4c006822509b06396871509140b7a79 (patch) | |
tree | 3455796f8c48fe8c5f202fe3044580c8fe7d8930 /src/nvim/mark.c | |
parent | 794981d9bed7048fb3ee1ada38fcf1ebdace4c53 (diff) | |
download | rneovim-0a81ec14a4c006822509b06396871509140b7a79.tar.gz rneovim-0a81ec14a4c006822509b06396871509140b7a79.tar.bz2 rneovim-0a81ec14a4c006822509b06396871509140b7a79.zip |
fix(api): better topline adjustments in nvim_buf_set_lines
Some more reasonable defaults for topline:
- if topline was replaced with another line, that now becomes topline
- if line was inserted just before topline, display it. This is more
similar to the previous API behavior.
Diffstat (limited to 'src/nvim/mark.c')
-rw-r--r-- | src/nvim/mark.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 584a6c5827..39fc623676 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1249,7 +1249,8 @@ void mark_adjust_buf(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount if (line1 <= 1) { win->w_topline = 1; } else { - win->w_topline = line1 - 1; + // api: if the deleted region was replaced with new contents, display that + win->w_topline = (by_api && amount_after > line1 - line2 - 1) ? line1 : line1 - 1; } } else if (win->w_topline > line1) { // keep topline on the same line, unless inserting just @@ -1257,7 +1258,9 @@ void mark_adjust_buf(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount win->w_topline += amount; } win->w_topfill = 0; - } else if (amount_after && win->w_topline > line2) { + // api: display new line if inserted right at topline + // TODO(bfredl): maybe always? + } else if (amount_after && win->w_topline > line2 + (by_api ? 1 : 0)) { win->w_topline += amount_after; win->w_topfill = 0; } |