mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	Add v:event.visual during TextYankPost (#12382)
				
					
				
			* propagate visual selection to textyankpost event * adapt tests * add docs * also adapt oldtest
This commit is contained in:
		| @@ -844,6 +844,7 @@ TextYankPost			Just after a |yank| or |deleting| command, but not | |||||||
| 				    regcontents | 				    regcontents | ||||||
| 				    regname | 				    regname | ||||||
| 				    regtype | 				    regtype | ||||||
|  | 				    visual | ||||||
| 				The `inclusive` flag combined with the |'[| | 				The `inclusive` flag combined with the |'[| | ||||||
| 				and |']| marks can be used to calculate the | 				and |']| marks can be used to calculate the | ||||||
| 				precise region of the operation. | 				precise region of the operation. | ||||||
|   | |||||||
| @@ -1591,6 +1591,8 @@ v:event		Dictionary of event data for the current |autocommand|.  Valid | |||||||
| 					operation. | 					operation. | ||||||
| 			regtype		Type of register as returned by | 			regtype		Type of register as returned by | ||||||
| 					|getregtype()|. | 					|getregtype()|. | ||||||
|  | 			visual		Selection is visual (as opposed to, | ||||||
|  | 					e.g., via motion).	 | ||||||
| 			completed_item    Current selected complete item on | 			completed_item    Current selected complete item on | ||||||
| 					|CompleteChanged|, Is `{}` when no complete | 					|CompleteChanged|, Is `{}` when no complete | ||||||
| 					item selected. | 					item selected. | ||||||
|   | |||||||
| @@ -705,6 +705,10 @@ the highlight via | |||||||
| > | > | ||||||
|  au TextYankPost * silent! lua require'vim.highlight'.on_yank("IncSearch", 500) |  au TextYankPost * silent! lua require'vim.highlight'.on_yank("IncSearch", 500) | ||||||
| < | < | ||||||
|  | If you want to exclude visual selections from highlighting on yank, use | ||||||
|  | > | ||||||
|  | au TextYankPost * silent! lua return (not vim.v.event.visual) and require'vim.highlight'.on_yank() | ||||||
|  | < | ||||||
|  |  | ||||||
| vim.highlight.on_yank([{higroup}, {timeout}, {event}])  | vim.highlight.on_yank([{higroup}, {timeout}, {event}])  | ||||||
|                                                     *vim.highlight.on_yank()* |                                                     *vim.highlight.on_yank()* | ||||||
|   | |||||||
| @@ -2748,6 +2748,10 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) | |||||||
|   buf[1] = NUL; |   buf[1] = NUL; | ||||||
|   tv_dict_add_str(dict, S_LEN("operator"), buf); |   tv_dict_add_str(dict, S_LEN("operator"), buf); | ||||||
|  |  | ||||||
|  |   // Selection type: visual or not. | ||||||
|  |   tv_dict_add_special(dict, S_LEN("visual"), | ||||||
|  |                       oap->is_VIsual ? kSpecialVarTrue : kSpecialVarFalse); | ||||||
|  |  | ||||||
|   tv_dict_set_keys_readonly(dict); |   tv_dict_set_keys_readonly(dict); | ||||||
|   textlock++; |   textlock++; | ||||||
|   apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, false, curbuf); |   apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, false, curbuf); | ||||||
|   | |||||||
| @@ -1246,23 +1246,23 @@ func Test_TextYankPost() | |||||||
|  |  | ||||||
|   norm "ayiw |   norm "ayiw | ||||||
|   call assert_equal( |   call assert_equal( | ||||||
|     \{'regcontents': ['foo'], 'inclusive': v:true, 'regname': 'a', 'operator': 'y', 'regtype': 'v'}, |     \{'regcontents': ['foo'], 'inclusive': v:true, 'regname': 'a', 'operator': 'y', 'visual': v:false, 'regtype': 'v'}, | ||||||
|     \g:event) |     \g:event) | ||||||
|   norm y_ |   norm y_ | ||||||
|   call assert_equal( |   call assert_equal( | ||||||
|     \{'regcontents': ['foo'], 'inclusive': v:false, 'regname': '',  'operator': 'y', 'regtype': 'V'}, |     \{'regcontents': ['foo'], 'inclusive': v:false, 'regname': '',  'operator': 'y', 'visual': v:false, 'regtype': 'V'}, | ||||||
|     \g:event) |     \g:event) | ||||||
|   call feedkeys("\<C-V>y", 'x') |   call feedkeys("\<C-V>y", 'x') | ||||||
|   call assert_equal( |   call assert_equal( | ||||||
|     \{'regcontents': ['f'], 'inclusive': v:true, 'regname': '',  'operator': 'y', 'regtype': "\x161"}, |     \{'regcontents': ['f'], 'inclusive': v:true, 'regname': '',  'operator': 'y', 'visual': v:true, 'regtype': "\x161"}, | ||||||
|     \g:event) |     \g:event) | ||||||
|   norm "xciwbar |   norm "xciwbar | ||||||
|   call assert_equal( |   call assert_equal( | ||||||
|     \{'regcontents': ['foo'], 'inclusive': v:true, 'regname': 'x', 'operator': 'c', 'regtype': 'v'}, |     \{'regcontents': ['foo'], 'inclusive': v:true, 'regname': 'x', 'operator': 'c', 'visual': v:false, 'regtype': 'v'}, | ||||||
|     \g:event) |     \g:event) | ||||||
|   norm "bdiw |   norm "bdiw | ||||||
|   call assert_equal( |   call assert_equal( | ||||||
|     \{'regcontents': ['bar'], 'inclusive': v:true, 'regname': 'b', 'operator': 'd', 'regtype': 'v'}, |     \{'regcontents': ['bar'], 'inclusive': v:true, 'regname': 'b', 'operator': 'd', 'visual': v:false, 'regtype': 'v'}, | ||||||
|     \g:event) |     \g:event) | ||||||
|  |  | ||||||
|   call assert_equal({}, v:event) |   call assert_equal({}, v:event) | ||||||
|   | |||||||
| @@ -27,7 +27,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(1, eval('g:count')) |     eq(1, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -40,7 +41,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'baz ' }, |       regcontents = { 'baz ' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'v' |       regtype = 'v', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(2, eval('g:count')) |     eq(2, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -50,7 +52,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo', 'baz' }, |       regcontents = { 'foo', 'baz' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = "\0223" -- ^V + block width |       regtype = "\0223", -- ^V + block width | ||||||
|  |       visual = true | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(3, eval('g:count')) |     eq(3, eval('g:count')) | ||||||
|   end) |   end) | ||||||
| @@ -62,7 +65,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|  |  | ||||||
|     command('set debug=msg') |     command('set debug=msg') | ||||||
| @@ -92,7 +96,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(1, eval('g:count')) |     eq(1, eval('g:count')) | ||||||
|     eq({ 'foo\nbar' }, funcs.getreg('+',1,1)) |     eq({ 'foo\nbar' }, funcs.getreg('+',1,1)) | ||||||
| @@ -105,7 +110,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'd', |       operator = 'd', | ||||||
|       regcontents = { 'foo' }, |       regcontents = { 'foo' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'v' |       regtype = 'v', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(1, eval('g:count')) |     eq(1, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -115,7 +121,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'd', |       operator = 'd', | ||||||
|       regcontents = { '\nbar' }, |       regcontents = { '\nbar' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(2, eval('g:count')) |     eq(2, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -125,7 +132,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'c', |       operator = 'c', | ||||||
|       regcontents = { 'baz' }, |       regcontents = { 'baz' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'v' |       regtype = 'v', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(3, eval('g:count')) |     eq(3, eval('g:count')) | ||||||
|   end) |   end) | ||||||
| @@ -153,7 +161,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'bar' }, |       regcontents = { 'bar' }, | ||||||
|       regname = 'b', |       regname = 'b', | ||||||
|       regtype = 'v' |       regtype = 'v', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|  |  | ||||||
|     feed('"*yy') |     feed('"*yy') | ||||||
| @@ -162,7 +171,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '*', |       regname = '*', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|  |  | ||||||
|     command("set clipboard=unnamed") |     command("set clipboard=unnamed") | ||||||
| @@ -174,7 +184,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|  |  | ||||||
|     feed('"*yy') |     feed('"*yy') | ||||||
| @@ -183,7 +194,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '*', |       regname = '*', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
| @@ -194,7 +206,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'd', |       operator = 'd', | ||||||
|       regcontents = { 'foo\nbar' }, |       regcontents = { 'foo\nbar' }, | ||||||
|       regname = '+', |       regname = '+', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(1, eval('g:count')) |     eq(1, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -204,7 +217,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'baz text' }, |       regcontents = { 'baz text' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(2, eval('g:count')) |     eq(2, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -214,7 +228,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'y', |       operator = 'y', | ||||||
|       regcontents = { 'baz ' }, |       regcontents = { 'baz ' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'v' |       regtype = 'v', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(3, eval('g:count')) |     eq(3, eval('g:count')) | ||||||
|  |  | ||||||
| @@ -224,7 +239,8 @@ describe('TextYankPost', function() | |||||||
|       operator = 'd', |       operator = 'd', | ||||||
|       regcontents = { 'baz text' }, |       regcontents = { 'baz text' }, | ||||||
|       regname = '', |       regname = '', | ||||||
|       regtype = 'V' |       regtype = 'V', | ||||||
|  |       visual = false | ||||||
|     }, eval('g:event')) |     }, eval('g:event')) | ||||||
|     eq(4, eval('g:count')) |     eq(4, eval('g:count')) | ||||||
|   end) |   end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Christian Clason
					Christian Clason