mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	'inccommand': preserve 'modified'
During the live preview, the buffer-local 'modified' flag should not be changed.
This commit is contained in:
		| @@ -3142,6 +3142,7 @@ buf_T *do_sub(exarg_T *eap) | |||||||
|   pos_T old_cursor = curwin->w_cursor; |   pos_T old_cursor = curwin->w_cursor; | ||||||
|   int start_nsubs; |   int start_nsubs; | ||||||
|   int save_ma = 0; |   int save_ma = 0; | ||||||
|  |   int save_b_changed = curbuf->b_changed; | ||||||
|  |  | ||||||
|   if (!global_busy) { |   if (!global_busy) { | ||||||
|     sub_nsubs = 0; |     sub_nsubs = 0; | ||||||
| @@ -3971,6 +3972,8 @@ skip: | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     curbuf->b_changed = save_b_changed;  // preserve 'modified' during preview | ||||||
|  |     // set_option_value((char_u *)"modified", 0L, NULL, OPT_LOCAL); | ||||||
|     preview_buf = show_sub(pat, sub, eap->line1, eap->line2, &matched_lines); |     preview_buf = show_sub(pat, sub, eap->line1, eap->line2, &matched_lines); | ||||||
|  |  | ||||||
|   } else if (*p_icm != NUL && eap->is_live) { |   } else if (*p_icm != NUL && eap->is_live) { | ||||||
| @@ -6014,9 +6017,8 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Shows the effects of the current :substitute command being typed | /// Shows the effects of the :substitute command being typed ('inccommand'). | ||||||
| /// ('inccommand'). If inccommand=split, shows a preview window then later | /// If inccommand=split, shows a preview window and later restores the layout. | ||||||
| /// restores the layout. |  | ||||||
| static buf_T *show_sub(char_u *pat, char_u *sub, linenr_T line1, linenr_T line2, | static buf_T *show_sub(char_u *pat, char_u *sub, linenr_T line1, linenr_T line2, | ||||||
|                        MatchedLineVec *matched_lines) |                        MatchedLineVec *matched_lines) | ||||||
|   FUNC_ATTR_NONNULL_ALL |   FUNC_ATTR_NONNULL_ALL | ||||||
| @@ -6050,7 +6052,7 @@ static buf_T *show_sub(char_u *pat, char_u *sub, linenr_T line1, linenr_T line2, | |||||||
|     buf_open_special(preview_buf ? bufnr : 0, "[Preview]", "incsub"); |     buf_open_special(preview_buf ? bufnr : 0, "[Preview]", "incsub"); | ||||||
|     buf_clear(); |     buf_clear(); | ||||||
|     preview_buf = curbuf; |     preview_buf = curbuf; | ||||||
|     set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL); |     set_option_value((char_u *)"bufhidden", 0L, (char_u *)"hide", OPT_LOCAL); | ||||||
|     bufnr = preview_buf->handle; |     bufnr = preview_buf->handle; | ||||||
|     curbuf->b_p_bl = false; |     curbuf->b_p_bl = false; | ||||||
|     curbuf->b_p_ma = true; |     curbuf->b_p_ma = true; | ||||||
|   | |||||||
| @@ -1594,6 +1594,7 @@ static int command_line_changed(CommandLineState *s) | |||||||
|   } else if (s->firstc == ':' |   } else if (s->firstc == ':' | ||||||
|              && KeyTyped            // only if interactive |              && KeyTyped            // only if interactive | ||||||
|              && *p_icm != NUL       // 'inccommand' is set |              && *p_icm != NUL       // 'inccommand' is set | ||||||
|  |              && curbuf->b_p_ma      // buffer is modifiable | ||||||
|              && cmdline_star == 0   // not typing a password |              && cmdline_star == 0   // not typing a password | ||||||
|              && cmd_is_live(ccline.cmdbuff)) { |              && cmd_is_live(ccline.cmdbuff)) { | ||||||
|     // process a "live" command ('inccommand') |     // process a "live" command ('inccommand') | ||||||
|   | |||||||
| @@ -610,6 +610,30 @@ describe(":substitute, inccommand=split", function() | |||||||
|     screen:detach() |     screen:detach() | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|  |   it("preserves 'modified' buffer flag", function() | ||||||
|  |     execute("set nomodified") | ||||||
|  |     feed(":%s/tw") | ||||||
|  |     screen:expect([[ | ||||||
|  |       Inc substitution on           | | ||||||
|  |       two lines                     | | ||||||
|  |                                     | | ||||||
|  |       {15:~                             }| | ||||||
|  |       {15:~                             }| | ||||||
|  |       {11:[No Name]                     }| | ||||||
|  |       |2| two lines                 | | ||||||
|  |       |4| two lines                 | | ||||||
|  |                                     | | ||||||
|  |       {15:~                             }| | ||||||
|  |       {15:~                             }| | ||||||
|  |       {15:~                             }| | ||||||
|  |       {15:~                             }| | ||||||
|  |       {10:[Preview]                     }| | ||||||
|  |       :%s/tw^                        | | ||||||
|  |     ]]) | ||||||
|  |     feed([[<C-\><C-N>]])  -- Cancel the :substitute command. | ||||||
|  |     eq(0, eval("&modified")) | ||||||
|  |   end) | ||||||
|  |  | ||||||
|   it('shows split window when typing the pattern', function() |   it('shows split window when typing the pattern', function() | ||||||
|     feed(":%s/tw") |     feed(":%s/tw") | ||||||
|     screen:expect([[ |     screen:expect([[ | ||||||
| @@ -957,7 +981,7 @@ describe(":substitute, 'inccommand' with a failing expression", function() | |||||||
|     common_setup(screen, case, default_text) |     common_setup(screen, case, default_text) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   it('in the pattern does nothing for', function() |   it('in the pattern does nothing', function() | ||||||
|     for _, case in pairs(cases) do |     for _, case in pairs(cases) do | ||||||
|       refresh(case) |       refresh(case) | ||||||
|       execute("set inccommand=" .. case) |       execute("set inccommand=" .. case) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes