summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0245
blob: 04698cb1995aaeac8759c52dcc6431aca03c77e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0245
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0245
Problem:    Calling setline() in TextChangedI autocmd breaks undo. (Jason
            Felice)
Solution:   Don't save lines for undo when already saved. (closes #3291)
Files:	    src/edit.c, src/testdir/test_autocmd.vim


*** ../vim-8.1.0244/src/edit.c	2018-08-07 14:55:04.905259782 +0200
--- src/edit.c	2018-08-07 18:26:35.026760346 +0200
***************
*** 1722,1732 ****
--- 1722,1740 ----
      {
  	aco_save_T	aco;
  
+ 	// Sync undo when the autocommand calls setline() or append(), so that
+ 	// it can be undone separately.
+ 	u_sync_once = 2;
+ 
  	// save and restore curwin and curbuf, in case the autocmd changes them
  	aucmd_prepbuf(&aco, curbuf);
  	apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf);
  	aucmd_restbuf(&aco);
  	curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
+ 
+ 	if (u_sync_once == 1)
+ 	    ins_need_undo = TRUE;
+ 	u_sync_once = 0;
      }
  
  #ifdef FEAT_INS_EXPAND
*** ../vim-8.1.0244/src/testdir/test_autocmd.vim	2018-04-28 20:01:18.000000000 +0200
--- src/testdir/test_autocmd.vim	2018-08-07 18:58:19.655939116 +0200
***************
*** 587,593 ****
    " Cleanup
    au! OptionSet
    for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp']
!     exe printf(":set %s&vi", opt)
    endfor
    call test_override('starting', 0)
    delfunc! AutoCommandOptionSet
--- 587,593 ----
    " Cleanup
    au! OptionSet
    for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp']
!     exe printf(":set %s&vim", opt)
    endfor
    call test_override('starting', 0)
    delfunc! AutoCommandOptionSet
***************
*** 1313,1318 ****
--- 1313,1343 ----
    bw!
  endfunc
  
+ let g:setline_handled = v:false
+ func! SetLineOne()
+   if !g:setline_handled
+     call setline(1, "(x)")
+     let g:setline_handled = v:true
+   endif
+ endfunc
+ 
+ func Test_TextChangedI_with_setline()
+   new
+   call test_override('char_avail', 1)
+   autocmd TextChangedI <buffer> call SetLineOne()
+   call feedkeys("i(\<CR>\<Esc>", 'tx')
+   call assert_equal('(', getline(1))
+   call assert_equal('x)', getline(2))
+   undo
+   call assert_equal('(', getline(1))
+   call assert_equal('', getline(2))
+   undo
+   call assert_equal('', getline(1))
+ 
+   call test_override('starting', 0)
+   bwipe!
+ endfunc
+ 
  func Test_Changed_FirstTime()
    if !has('terminal') || has('gui_running')
      return
*** ../vim-8.1.0244/src/version.c	2018-08-07 17:38:36.995674625 +0200
--- src/version.c	2018-08-07 19:04:25.389813721 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     245,
  /**/

-- 
ARTHUR:   Ni!
BEDEVERE: Nu!
ARTHUR:   No.  Ni!  More like this. "Ni"!
BEDEVERE: Ni, ni, ni!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///