diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-17 08:09:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-17 08:09:51 +0800 |
commit | f72cb97fa0db63e14363af60f45d0f2a0a84cc27 (patch) | |
tree | 922c64f58ddf328e86df4a1d38d77b8dbe10407b /src/nvim/ops.c | |
parent | bbdded5cf7dee5d973f8b659a5748f253755d8d5 (diff) | |
download | rneovim-f72cb97fa0db63e14363af60f45d0f2a0a84cc27.tar.gz rneovim-f72cb97fa0db63e14363af60f45d0f2a0a84cc27.tar.bz2 rneovim-f72cb97fa0db63e14363af60f45d0f2a0a84cc27.zip |
vim-patch:9.0.1208: code is indented more than necessary (#21846)
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes vim/vim#11819)
https://github.com/vim/vim/commit/a41e221935edab62672a15123af48f4f14ac1c7d
Cherry-pick check_text_or_curbuf_locked() from patch 9.0.0947.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 34432c58db..73707e4122 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1785,10 +1785,12 @@ setmarks: /// Used for deletion. static void mb_adjust_opend(oparg_T *oap) { - if (oap->inclusive) { - char *p = ml_get(oap->end.lnum); - oap->end.col += utf_cp_tail_off(p, p + oap->end.col); + if (!oap->inclusive) { + return; } + + char *p = ml_get(oap->end.lnum); + oap->end.col += utf_cp_tail_off(p, p + oap->end.col); } /// Put character 'c' at position 'lp' @@ -3711,20 +3713,23 @@ void adjust_cursor_eol(void) { unsigned int cur_ve_flags = get_ve_flags(); - if (curwin->w_cursor.col > 0 - && gchar_cursor() == NUL - && (cur_ve_flags & VE_ONEMORE) == 0 - && !(restart_edit || (State & MODE_INSERT))) { - // Put the cursor on the last character in the line. - dec_cursor(); + const bool adj_cursor = (curwin->w_cursor.col > 0 + && gchar_cursor() == NUL + && (cur_ve_flags & VE_ONEMORE) == 0 + && !(restart_edit || (State & MODE_INSERT))); + if (!adj_cursor) { + return; + } - if (cur_ve_flags == VE_ALL) { - colnr_T scol, ecol; + // Put the cursor on the last character in the line. + dec_cursor(); - // Coladd is set to the width of the last character. - getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); - curwin->w_cursor.coladd = ecol - scol + 1; - } + if (cur_ve_flags == VE_ALL) { + colnr_T scol, ecol; + + // Coladd is set to the width of the last character. + getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); + curwin->w_cursor.coladd = ecol - scol + 1; } } @@ -4205,11 +4210,13 @@ static bool reset_lbr(void) /// Restore 'linebreak' and take care of side effects. static void restore_lbr(bool lbr_saved) { - if (!curwin->w_p_lbr && lbr_saved) { - // changing 'linebreak' may require w_virtcol to be updated - curwin->w_p_lbr = true; - curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); + if (curwin->w_p_lbr || !lbr_saved) { + return; } + + // changing 'linebreak' may require w_virtcol to be updated + curwin->w_p_lbr = true; + curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); } /// prepare a few things for block mode yank/delete/tilde |