mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	| @@ -1249,6 +1249,10 @@ void enter_buffer(buf_T *buf) | ||||
|   /* mark cursor position as being invalid */ | ||||
|   curwin->w_valid = 0; | ||||
|  | ||||
|   if (buf->terminal) { | ||||
|     terminal_resize(buf->terminal, curwin->w_width, curwin->w_height); | ||||
|   } | ||||
|  | ||||
|   /* Make sure the buffer is loaded. */ | ||||
|   if (curbuf->b_ml.ml_mfp == NULL) {    /* need to load the file */ | ||||
|     /* If there is no filetype, allow for detecting one.  Esp. useful for | ||||
|   | ||||
| @@ -348,15 +348,6 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) | ||||
|     height = (uint16_t)curheight; | ||||
|   } | ||||
|  | ||||
|   // The new width/height are the minimum for all windows that display the | ||||
|   // terminal in the current tab. | ||||
|   FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { | ||||
|     if (!wp->w_closing && wp->w_buffer->terminal == term) { | ||||
|       width = (uint16_t)MIN(width, (uint16_t)(wp->w_width - win_col_off(wp))); | ||||
|       height = (uint16_t)MIN(height, (uint16_t)wp->w_height); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (curheight == height && curwidth == width) { | ||||
|     return; | ||||
|   } | ||||
|   | ||||
| @@ -3613,6 +3613,10 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri | ||||
|  | ||||
|   /* Change directories when the 'acd' option is set. */ | ||||
|   do_autochdir(); | ||||
|  | ||||
|   if (curbuf->terminal) { | ||||
|     terminal_resize(curbuf->terminal, curwin->w_width, curwin->w_height); | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -112,7 +112,7 @@ describe('terminal mouse', function() | ||||
|           line28                   |line28                  | | ||||
|           line29                   |line29                  | | ||||
|           line30                   |line30                  | | ||||
|           rows: 5, cols: 24        |rows: 5, cols: 24       | | ||||
|           rows: 5, cols: 25        |rows: 5, cols: 25       | | ||||
|           {2:^ }                        |{2: }                       | | ||||
|           ==========                ==========              | | ||||
|                                                             | | ||||
| @@ -122,7 +122,7 @@ describe('terminal mouse', function() | ||||
|             1 ^                     |line28                  | | ||||
|           ~                        |line29                  | | ||||
|           ~                        |line30                  | | ||||
|           ~                        |rows: 5, cols: 24       | | ||||
|           ~                        |rows: 5, cols: 25       | | ||||
|           ~                        |{2: }                       | | ||||
|           ==========                ==========              | | ||||
|           :enew | set number                                | | ||||
| @@ -132,16 +132,16 @@ describe('terminal mouse', function() | ||||
|            27 line                 |line28                  | | ||||
|            28 line                 |line29                  | | ||||
|            29 line                 |line30                  | | ||||
|            30 line                 |rows: 5, cols: 24       | | ||||
|            30 line                 |rows: 5, cols: 25       | | ||||
|            31 ^                     |{2: }                       | | ||||
|           ==========                ==========              | | ||||
|                                                             | | ||||
|         ]]) | ||||
|         feed('<c-w>li') | ||||
|         screen:expect([[ | ||||
|            27 line                 |line28                  | | ||||
|            28 line                 |line29                  | | ||||
|            29 line                 |line30                  | | ||||
|            27 line                 |line29                  | | ||||
|            28 line                 |line30                  | | ||||
|            29 line                 |rows: 5, cols: 25       | | ||||
|            30 line                 |rows: 5, cols: 24       | | ||||
|            31                      |{1: }                       | | ||||
|           ==========                ==========              | | ||||
| @@ -151,8 +151,8 @@ describe('terminal mouse', function() | ||||
|         thelpers.enable_mouse() | ||||
|         thelpers.feed_data('mouse enabled\n') | ||||
|         screen:expect([[ | ||||
|            27 line                 |line29                  | | ||||
|            28 line                 |line30                  | | ||||
|            27 line                 |line30                  | | ||||
|            28 line                 |rows: 5, cols: 25       | | ||||
|            29 line                 |rows: 5, cols: 24       | | ||||
|            30 line                 |mouse enabled           | | ||||
|            31                      |{1: }                       | | ||||
| @@ -164,8 +164,8 @@ describe('terminal mouse', function() | ||||
|       it('wont lose focus if another window is scrolled', function() | ||||
|         feed('<MouseDown><0,0><MouseDown><0,0>') | ||||
|         screen:expect([[ | ||||
|            21 line                 |line29                  | | ||||
|            22 line                 |line30                  | | ||||
|            21 line                 |line30                  | | ||||
|            22 line                 |rows: 5, cols: 25       | | ||||
|            23 line                 |rows: 5, cols: 24       | | ||||
|            24 line                 |mouse enabled           | | ||||
|            25 line                 |{1: }                       | | ||||
| @@ -174,8 +174,8 @@ describe('terminal mouse', function() | ||||
|         ]]) | ||||
|         feed('<S-MouseUp><0,0>') | ||||
|         screen:expect([[ | ||||
|            26 line                 |line29                  | | ||||
|            27 line                 |line30                  | | ||||
|            26 line                 |line30                  | | ||||
|            27 line                 |rows: 5, cols: 25       | | ||||
|            28 line                 |rows: 5, cols: 24       | | ||||
|            29 line                 |mouse enabled           | | ||||
|            30 line                 |{1: }                       | | ||||
| @@ -187,8 +187,8 @@ describe('terminal mouse', function() | ||||
|       it('will lose focus if another window is clicked', function() | ||||
|         feed('<LeftMouse><5,1>') | ||||
|         screen:expect([[ | ||||
|            27 line                 |line29                  | | ||||
|            28 l^ine                 |line30                  | | ||||
|            27 line                 |line30                  | | ||||
|            28 l^ine                 |rows: 5, cols: 25       | | ||||
|            29 line                 |rows: 5, cols: 24       | | ||||
|            30 line                 |mouse enabled           | | ||||
|            31                      |{2: }                       | | ||||
|   | ||||
| @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) | ||||
| local thelpers = require('test.functional.terminal.helpers') | ||||
| local feed, clear = helpers.feed, helpers.clear | ||||
| local wait = helpers.wait | ||||
|  | ||||
| local execute = helpers.execute | ||||
|  | ||||
| describe('terminal window', function() | ||||
|   local screen | ||||
| @@ -12,6 +12,23 @@ describe('terminal window', function() | ||||
|     screen = thelpers.screen_setup() | ||||
|   end) | ||||
|  | ||||
|   it('resets its size when entering terminal buffer', function() | ||||
|     feed('<c-\\><c-n>') | ||||
|     execute('set hidden') | ||||
|     execute('edit foo') | ||||
|     execute('doautoall SessionLoadPost') | ||||
|     execute('silent bnext') | ||||
|     screen:expect([[ | ||||
|       tty ready                                         | | ||||
|       {2: }                                                 | | ||||
|                                                         | | ||||
|                                                         | | ||||
|                                                         | | ||||
|       ^                                                  | | ||||
|       :silent bnext                                     | | ||||
|     ]]) | ||||
|   end) | ||||
|  | ||||
|   describe('with colorcolumn set', function() | ||||
|     before_each(function() | ||||
|       feed('<c-\\><c-n>') | ||||
|   | ||||
| @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) | ||||
| local thelpers = require('test.functional.terminal.helpers') | ||||
| local clear = helpers.clear | ||||
| local feed, nvim = helpers.feed, helpers.nvim | ||||
| local execute = helpers.execute | ||||
|  | ||||
| describe('terminal', function() | ||||
|   local screen | ||||
| @@ -21,6 +22,49 @@ describe('terminal', function() | ||||
|     screen:detach() | ||||
|   end) | ||||
|  | ||||
|   it('resets its size when entering terminal window', function() | ||||
|     feed('<c-\\><c-n>') | ||||
|     execute('2split') | ||||
|     screen:expect([[ | ||||
|       tty ready                                         | | ||||
|       ^rows: 2, cols: 50                                 | | ||||
|       ==========                                        | | ||||
|       tty ready                                         | | ||||
|       rows: 2, cols: 50                                 | | ||||
|       {2: }                                                 | | ||||
|       ~                                                 | | ||||
|       ~                                                 | | ||||
|       ==========                                        | | ||||
|                                                         | | ||||
|     ]]) | ||||
|     execute('wincmd p') | ||||
|     screen:expect([[ | ||||
|       tty ready                                         | | ||||
|       rows: 2, cols: 50                                 | | ||||
|       ==========                                        | | ||||
|       tty ready                                         | | ||||
|       rows: 2, cols: 50                                 | | ||||
|       rows: 5, cols: 50                                 | | ||||
|       {2: }                                                 | | ||||
|       ^                                                  | | ||||
|       ==========                                        | | ||||
|       :wincmd p                                         | | ||||
|     ]]) | ||||
|     execute('wincmd p') | ||||
|     screen:expect([[ | ||||
|       rows: 5, cols: 50                                 | | ||||
|       ^rows: 2, cols: 50                                 | | ||||
|       ==========                                        | | ||||
|       rows: 5, cols: 50                                 | | ||||
|       rows: 2, cols: 50                                 | | ||||
|       {2: }                                                 | | ||||
|       ~                                                 | | ||||
|       ~                                                 | | ||||
|       ==========                                        | | ||||
|       :wincmd p                                         | | ||||
|     ]]) | ||||
|   end) | ||||
|  | ||||
|   describe('when the screen is resized', function() | ||||
|     it('will forward a resize request to the program', function() | ||||
|       screen:try_resize(screen._width + 3, screen._height + 5) | ||||
| @@ -51,87 +95,4 @@ describe('terminal', function() | ||||
|       ]]) | ||||
|     end) | ||||
|   end) | ||||
|  | ||||
|   describe('split horizontally', function() | ||||
|     before_each(function() | ||||
|       nvim('command', 'sp') | ||||
|     end) | ||||
|  | ||||
|     local function reduce_height() | ||||
|       screen:expect([[ | ||||
|         tty ready                                         | | ||||
|         rows: 3, cols: 50                                 | | ||||
|         {1: }                                                 | | ||||
|         ~                                                 | | ||||
|         ==========                                        | | ||||
|         tty ready                                         | | ||||
|         rows: 3, cols: 50                                 | | ||||
|         {2: }                                                 | | ||||
|         ==========                                        | | ||||
|         -- TERMINAL --                                    | | ||||
|       ]]) | ||||
|     end | ||||
|  | ||||
|     it('uses the minimum height of all window displaying it', reduce_height) | ||||
|  | ||||
|     describe('and then vertically', function() | ||||
|       before_each(function() | ||||
|         reduce_height() | ||||
|         nvim('command', 'vsp') | ||||
|       end) | ||||
|  | ||||
|       local function reduce_width() | ||||
|         screen:expect([[ | ||||
|           rows: 3, cols: 50        |rows: 3, cols: 50       | | ||||
|           rows: 3, cols: 24        |rows: 3, cols: 24       | | ||||
|           {1: }                        |{2: }                       | | ||||
|           ~                        |~                       | | ||||
|           ==========                ==========              | | ||||
|           rows: 3, cols: 50                                 | | ||||
|           rows: 3, cols: 24                                 | | ||||
|           {2: }                                                 | | ||||
|           ==========                                        | | ||||
|           -- TERMINAL --                                    | | ||||
|         ]]) | ||||
|         feed('<c-\\><c-n>gg') | ||||
|         screen:expect([[ | ||||
|           ^tty ready                |rows: 3, cols: 50       | | ||||
|           rows: 3, cols: 50        |rows: 3, cols: 24       | | ||||
|           rows: 3, cols: 24        |{2: }                       | | ||||
|           {2: }                        |~                       | | ||||
|           ==========                ==========              | | ||||
|           rows: 3, cols: 50                                 | | ||||
|           rows: 3, cols: 24                                 | | ||||
|           {2: }                                                 | | ||||
|           ==========                                        | | ||||
|                                                             | | ||||
|         ]]) | ||||
|       end | ||||
|  | ||||
|       it('uses the minimum width of all window displaying it', reduce_width) | ||||
|  | ||||
|       describe('and then closes one of the vertical splits with q:', function() | ||||
|         before_each(function() | ||||
|           reduce_width() | ||||
|           nvim('command', 'q') | ||||
|           feed('<c-w>ja') | ||||
|         end) | ||||
|  | ||||
|         it('will restore the width', function() | ||||
|           screen:expect([[ | ||||
|             rows: 3, cols: 24                                 | | ||||
|             rows: 3, cols: 50                                 | | ||||
|             {2: }                                                 | | ||||
|             ~                                                 | | ||||
|             ==========                                        | | ||||
|             rows: 3, cols: 24                                 | | ||||
|             rows: 3, cols: 50                                 | | ||||
|             {1: }                                                 | | ||||
|             ==========                                        | | ||||
|             -- TERMINAL --                                    | | ||||
|           ]]) | ||||
|         end) | ||||
|       end) | ||||
|     end) | ||||
|   end) | ||||
| end) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes