From 08fc1ebbaa49e3110b65bddeed28d2e61a96f5d9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 11 Mar 2024 13:19:49 +0100 Subject: fix(api/buffer): fix handling of viewport of non-current buffer A lot of functions in move.c only worked for curwin, alternatively took a `wp` arg but still only work if that happens to be curwin. Refactor those that are needed for update_topline(wp) to work for any window. fixes #27723 fixes #27720 --- src/nvim/diff.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 2b3010e063..bc91c1e4c2 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1347,7 +1347,7 @@ void ex_diffsplit(exarg_T *eap) set_bufref(&old_curbuf, curbuf); // Need to compute w_fraction when no redraw happened yet. - validate_cursor(); + validate_cursor(curwin); set_fraction(curwin); // don't use a new tab page, each tab page has its own diffs @@ -1457,7 +1457,7 @@ void diff_win_options(win_T *wp, bool addbuf) foldUpdateAll(wp); // make sure topline is not halfway through a fold - changed_window_setting_win(wp); + changed_window_setting(wp); if (vim_strchr(p_sbo, 'h') == NULL) { do_cmdline_cmd("set sbo+=hor"); } @@ -1522,7 +1522,7 @@ void ex_diffoff(exarg_T *eap) // make sure topline is not halfway a fold and cursor is // invalidated - changed_window_setting_win(wp); + changed_window_setting(wp); // Note: 'sbo' is not restored, it's a global option. diff_buf_adjust(wp); @@ -2137,7 +2137,7 @@ int diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus) } // A closed fold never has filler lines. - if (hasFoldingWin(wp, lnum, NULL, NULL, true, NULL)) { + if (hasFolding(wp, lnum, NULL, NULL)) { return 0; } @@ -2451,8 +2451,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin) changed_line_abv_curs_win(towin); check_topfill(towin, false); - hasFoldingWin(towin, towin->w_topline, &towin->w_topline, - NULL, true, NULL); + hasFolding(towin, towin->w_topline, &towin->w_topline, NULL); } /// This is called when 'diffopt' is changed. @@ -2988,7 +2987,7 @@ theend: // Check that the cursor is on a valid character and update its // position. When there were filler lines the topline has become // invalid. - check_cursor(); + check_cursor(curwin); changed_line_abv_curs(); if (diff_need_update) { -- cgit From 090d1fd0b86897d2f5a80a600becf1525398ef30 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 13 Mar 2024 15:00:43 +0800 Subject: vim-patch:9.1.0172: More code can use ml_get_buf_len() instead of STRLEN() Problem: More code can use ml_get_buf_len() instead of STRLEN(). Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not set ml_line_textlen in ml_replace_len() if "has_props" is set, because "len_arg" also includes the size of text properties in that case. (zeertzjq) closes: vim/vim#14183 https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b --- src/nvim/diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index bc91c1e4c2..c680600d39 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -756,7 +756,7 @@ static int diff_write_buffer(buf_T *buf, mmfile_t *m, linenr_T start, linenr_T e // xdiff requires one big block of memory with all the text. for (linenr_T lnum = start; lnum <= end; lnum++) { - len += strlen(ml_get_buf(buf, lnum)) + 1; + len += (size_t)ml_get_buf_len(buf, lnum) + 1; } char *ptr = try_malloc(len); if (ptr == NULL) { -- cgit From c0daea3afd6a1e502e282a235a10643c785301f7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Mar 2024 17:10:20 +0800 Subject: vim-patch:9.1.0183: Wrong display or screenpos() result when toggling diff mode (#27882) Problem: Wrong display or screenpos() result when toggling diff mode. Solution: Reset w_skipcol when disabling 'wrap'. Reset w_leftcol when enabling 'wrap' (zeertzjq). fixes: vim/vim#14210 closes: vim/vim#14211 https://github.com/vim/vim/commit/9e7f1fc2f159d58b2a4cd4b7060bead126fead49 --- src/nvim/diff.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index c680600d39..39d9e9e978 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1429,6 +1429,7 @@ void diff_win_options(win_T *wp, bool addbuf) wp->w_p_wrap_save = wp->w_p_wrap; } wp->w_p_wrap = false; + wp->w_skipcol = 0; } if (!wp->w_p_diff) { @@ -1497,8 +1498,9 @@ void ex_diffoff(exarg_T *eap) wp->w_p_crb = wp->w_p_crb_save; } if (!(diff_flags & DIFF_FOLLOWWRAP)) { - if (!wp->w_p_wrap) { - wp->w_p_wrap = wp->w_p_wrap_save; + if (!wp->w_p_wrap && wp->w_p_wrap_save) { + wp->w_p_wrap = true; + wp->w_leftcol = 0; } } free_string_option(wp->w_p_fdm); -- cgit From 2214f9c19daa46a1fc37bcc14c017c092894a506 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 3 Feb 2024 12:57:03 +0600 Subject: refactor(options): remove `set_string_option_direct()` Problem: `set_string_option_direct()` contains a separate codepath specifically for setting string options. Not only is that unnecessary code duplication, but it's also limited to only string options. Solution: Replace `set_string_option_direct()` with `set_option_direct()` which calls `set_option()` under the hood. This reduces code duplication and allows directly setting an option of any type. --- src/nvim/diff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 39d9e9e978..ea846b46ec 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1438,7 +1438,8 @@ void diff_win_options(win_T *wp, bool addbuf) } wp->w_p_fdm_save = xstrdup(wp->w_p_fdm); } - set_string_option_direct_in_win(wp, kOptFoldmethod, "diff", OPT_LOCAL, 0); + set_option_direct_for(kOptFoldmethod, STATIC_CSTR_AS_OPTVAL("diff"), OPT_LOCAL, 0, kOptReqWin, + wp); if (!wp->w_p_diff) { wp->w_p_fen_save = wp->w_p_fen; -- cgit