diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2023-01-09 07:16:36 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-09 07:16:36 +0800 |
| commit | a174f4e53f0e111653e10d2df8aebe7c9fa0f73e (patch) | |
| tree | f1f8edde414073608020399de66518162ca6ad56 /src/nvim/fold.c | |
| parent | 904c13e6b572552a676efcaec640dfa8bd199e59 (diff) | |
| download | rneovim-a174f4e53f0e111653e10d2df8aebe7c9fa0f73e.tar.gz rneovim-a174f4e53f0e111653e10d2df8aebe7c9fa0f73e.tar.bz2 rneovim-a174f4e53f0e111653e10d2df8aebe7c9fa0f73e.zip | |
vim-patch:9.0.1158: code is indented more than necessary (#21697)
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes vim/vim#11787)
https://github.com/vim/vim/commit/7f8b2559a30e2e2a443c35b28e94c6b45ba7ae04
Omit reset_last_used_map(): only used in Vim9 script.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/fold.c')
| -rw-r--r-- | src/nvim/fold.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 6d85206d18..8b773b2eee 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -477,12 +477,15 @@ static void newFoldLevelWin(win_T *wp) /// Apply 'foldlevel' to all folds that don't contain the cursor. void foldCheckClose(void) { - if (*p_fcl != NUL) { // can only be "all" right now - checkupdate(curwin); - if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum, - (int)curwin->w_p_fdl)) { - changed_window_setting(); - } + if (*p_fcl == NUL) { + return; + } + + // can only be "all" right now + checkupdate(curwin); + if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum, + (int)curwin->w_p_fdl)) { + changed_window_setting(); } } @@ -1005,15 +1008,18 @@ void foldAdjustVisual(void) if (hasFolding(start->lnum, &start->lnum, NULL)) { start->col = 0; } - if (hasFolding(end->lnum, NULL, &end->lnum)) { - ptr = ml_get(end->lnum); - end->col = (colnr_T)strlen(ptr); - if (end->col > 0 && *p_sel == 'o') { - end->col--; - } - // prevent cursor from moving on the trail byte - mb_adjust_cursor(); + + if (!hasFolding(end->lnum, NULL, &end->lnum)) { + return; + } + + ptr = ml_get(end->lnum); + end->col = (colnr_T)strlen(ptr); + if (end->col > 0 && *p_sel == 'o') { + end->col--; } + // prevent cursor from moving on the trail byte + mb_adjust_cursor(); } // cursor_foldstart() {{{2 @@ -1115,10 +1121,12 @@ static int foldLevelWin(win_T *wp, linenr_T lnum) /// Check if the folds in window "wp" are invalid and update them if needed. static void checkupdate(win_T *wp) { - if (wp->w_foldinvalid) { - foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); // will update all - wp->w_foldinvalid = false; + if (!wp->w_foldinvalid) { + return; } + + foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); // will update all + wp->w_foldinvalid = false; } // setFoldRepeat() {{{2 |