aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fold.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/fold.c')
-rw-r--r--src/nvim/fold.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index ac3cf959c8..d964da371a 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -22,7 +22,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
@@ -166,7 +165,7 @@ bool hasFoldingWin(
int use_level = FALSE;
int maybe_small = FALSE;
garray_T *gap;
- int low_level = 0;;
+ int low_level = 0;
checkupdate(win);
/*
@@ -762,16 +761,12 @@ void clearFolding(win_T *win)
*/
void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
{
- if (compl_busy) {
- return;
- }
-
- fold_T *fp;
- if (wp->w_buffer->terminal) {
+ if (compl_busy || State & INSERT) {
return;
}
// Mark all folds from top to bot as maybe-small.
+ fold_T *fp;
(void)foldFind(&wp->w_folds, top, &fp);
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
&& fp->fd_top < bot) {
@@ -793,6 +788,19 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
}
}
+/// Updates folds when leaving insert-mode.
+void foldUpdateAfterInsert(void)
+{
+ if (foldmethodIsManual(curwin) // foldmethod=manual: No need to update.
+ // These foldmethods are too slow, do not auto-update on insert-leave.
+ || foldmethodIsSyntax(curwin) || foldmethodIsExpr(curwin)) {
+ return;
+ }
+
+ foldUpdateAll(curwin);
+ foldOpenCursor();
+}
+
/* foldUpdateAll() {{{2 */
/*
* Update all lines in a window for folding.
@@ -1600,7 +1608,7 @@ static void foldAddMarker(linenr_T lnum, char_u *marker, size_t markerlen)
STRLCPY(newline + line_len, marker, markerlen + 1);
else {
STRCPY(newline + line_len, cms);
- STRNCPY(newline + line_len + (p - cms), marker, markerlen);
+ memcpy(newline + line_len + (p - cms), marker, markerlen);
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
}
@@ -1665,7 +1673,8 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, size_t markerlen)
if (u_save(lnum - 1, lnum + 1) == OK) {
/* Make new line: text-before-marker + text-after-marker */
newline = xmalloc(STRLEN(line) - len + 1);
- STRNCPY(newline, line, p - line);
+ assert(p >= line);
+ memcpy(newline, line, (size_t)(p - line));
STRCPY(newline + (p - line), p + len);
ml_replace(lnum, newline, FALSE);
}