Skip to content

Commit 25ea054

Browse files
committed
patch 8.0.0300: cannot stop diffing hidden buffers
Problem: Cannot stop diffing hidden buffers. (Daniel Hahler) Solution: When using :diffoff! make the whole list if diffed buffers empty. (closes #736)
1 parent 6b40f30 commit 25ea054

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/diff.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ diff_buf_add(buf_T *buf)
138138
EMSGN(_("E96: Cannot diff more than %ld buffers"), DB_COUNT);
139139
}
140140

141+
/*
142+
* Remove all buffers to make diffs for.
143+
*/
144+
static void
145+
diff_buf_clear(void)
146+
{
147+
int i;
148+
149+
for (i = 0; i < DB_COUNT; ++i)
150+
if (curtab->tp_diffbuf[i] != NULL)
151+
{
152+
curtab->tp_diffbuf[i] = NULL;
153+
curtab->tp_diff_invalid = TRUE;
154+
diff_redraw(TRUE);
155+
}
156+
}
157+
141158
/*
142159
* Find buffer "buf" in the list of diff buffers for the current tab page.
143160
* Return its index or DB_COUNT if not found.
@@ -1257,6 +1274,10 @@ ex_diffoff(exarg_T *eap)
12571274
#endif
12581275
}
12591276

1277+
/* Also remove hidden buffers from the list. */
1278+
if (eap->forceit)
1279+
diff_buf_clear();
1280+
12601281
#ifdef FEAT_SCROLLBIND
12611282
/* Remove "hor" from from 'scrollopt' if there are no diff windows left. */
12621283
if (!diffwin && vim_strchr(p_sbo, 'h') != NULL)

src/testdir/test_diffmode.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,50 @@ func Test_diffoff()
212212
call setline(1, ['One', '', 'Two', 'Three'])
213213
diffthis
214214
redraw
215+
call assert_notequal(normattr, screenattr(1, 1))
215216
diffoff!
216217
redraw
217218
call assert_equal(normattr, screenattr(1, 1))
218219
bwipe!
219220
bwipe!
220221
endfunc
221222

223+
func Test_diffoff_hidden()
224+
set diffopt=filler,foldcolumn:0
225+
e! one
226+
call setline(1, ['Two', 'Three'])
227+
let normattr = screenattr(1, 1)
228+
diffthis
229+
botright vert new two
230+
call setline(1, ['One', 'Four'])
231+
diffthis
232+
redraw
233+
call assert_notequal(normattr, screenattr(1, 1))
234+
set hidden
235+
close
236+
redraw
237+
" diffing with hidden buffer two
238+
call assert_notequal(normattr, screenattr(1, 1))
239+
diffoff
240+
redraw
241+
call assert_equal(normattr, screenattr(1, 1))
242+
diffthis
243+
redraw
244+
" still diffing with hidden buffer two
245+
call assert_notequal(normattr, screenattr(1, 1))
246+
diffoff!
247+
redraw
248+
call assert_equal(normattr, screenattr(1, 1))
249+
diffthis
250+
redraw
251+
" no longer diffing with hidden buffer two
252+
call assert_equal(normattr, screenattr(1, 1))
253+
254+
bwipe!
255+
bwipe!
256+
set hidden& diffopt&
257+
endfunc
258+
222259
func Test_setting_cursor()
223260
new Xtest1
224261
put =range(1,90)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
300,
767769
/**/
768770
299,
769771
/**/

0 commit comments

Comments
 (0)