Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit144f64f

Browse files
committed
fix(terminal): do not trim whitespace that is actually in the terminal
1 parent2cd815c commit144f64f

File tree

4 files changed

+75
-13
lines changed

4 files changed

+75
-13
lines changed

‎src/nvim/terminal.c‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,27 +1314,22 @@ static void fetch_row(Terminal *term, int row, int end_col)
13141314
while (col<end_col) {
13151315
VTermScreenCellcell;
13161316
fetch_cell(term,row,col,&cell);
1317-
intcell_len=0;
13181317
if (cell.chars[0]) {
1318+
intcell_len=0;
13191319
for (inti=0;cell.chars[i];i++) {
13201320
cell_len+=utf_char2bytes((int)cell.chars[i],
13211321
(uint8_t*)ptr+cell_len);
13221322
}
1323-
}else {
1324-
*ptr=' ';
1325-
cell_len=1;
1326-
}
1327-
charc=*ptr;
1328-
ptr+=cell_len;
1329-
if (c!=' ') {
1330-
// only increase the line length if the last character is not whitespace
1323+
ptr+=cell_len;
13311324
line_len= (size_t)(ptr-term->textbuf);
1325+
}else {
1326+
*ptr++=' ';
13321327
}
13331328
col+=cell.width;
13341329
}
13351330

1336-
//trim trailing whitespace
1337-
term->textbuf[line_len]=0;
1331+
//end of line
1332+
term->textbuf[line_len]=NUL;
13381333
}
13391334

13401335
staticboolfetch_cell(Terminal*term,introw,intcol,VTermScreenCell*cell)

‎test/functional/api/buffer_updates_spec.lua‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,8 @@ describe('API: buffer events:', function()
785785

786786
localfunctionlines_subset(first,second)
787787
fori=1,#firstdo
788-
iffirst[i]~=second[i]then
788+
-- need to ignore trailing spaces
789+
iffirst[i]:gsub(' +$','')~=second[i]:gsub(' +$','')then
789790
returnfalse
790791
end
791792
end

‎test/functional/core/startup_spec.lua‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,13 @@ describe('sysinit', function()
475475

476476
it('fixed hang issue with -D (#12647)',function()
477477
localscreen
478-
screen=Screen.new(60,6)
478+
screen=Screen.new(60,7)
479479
screen:attach()
480480
command([[let g:id = termopen('"]]..nvim_prog..
481481
[[" -u NONE -i NONE --cmd "set noruler" -D')]])
482482
screen:expect([[
483483
^ |
484+
|
484485
Entering Debug mode. Type "cont" to continue. |
485486
cmd: augroup nvim_terminal |
486487
> |
@@ -491,6 +492,7 @@ describe('sysinit', function()
491492
screen:expect([[
492493
^ |
493494
~ |
495+
~ |
494496
[No Name] |
495497
|
496498
<" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All|

‎test/functional/terminal/cursor_spec.lua‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,38 @@ describe('buffer cursor position is correct in terminal without number column',
277277
end)
278278
end)
279279

280+
describe('in a line with no multibyte characters and some trailing spaces,',function()
281+
before_each(function()
282+
setup_ex_register('aaaaaaaa')
283+
end)
284+
285+
it('at the end',function()
286+
feed('<C-R>r')
287+
screen:expect([[
288+
|
289+
|
290+
|
291+
|
292+
Entering Ex mode. Type "visual" to go to Normal mode. |
293+
:aaaaaaaa {1: } |
294+
{3:-- TERMINAL --} |
295+
]])
296+
eq(':aaaaaaaa',eval('nvim_get_current_line()'))
297+
eq({6,13},eval('nvim_win_get_cursor(0)'))
298+
feed([[<C-\><C-N>]])
299+
screen:expect([[
300+
|
301+
|
302+
|
303+
|
304+
Entering Ex mode. Type "visual" to go to Normal mode. |
305+
:aaaaaaaa ^ {2: } |
306+
|
307+
]])
308+
eq({6,12},eval('nvim_win_get_cursor(0)'))
309+
end)
310+
end)
311+
280312
describe('in a line with single-cell multibyte characters and no trailing spaces,',function()
281313
before_each(function()
282314
setup_ex_register('µµµµµµµµ')
@@ -630,6 +662,38 @@ describe('buffer cursor position is correct in terminal with number column', fun
630662
end)
631663
end)
632664

665+
describe('in a line with no multibyte characters and some trailing spaces,',function()
666+
before_each(function()
667+
setup_ex_register('aaaaaaaa')
668+
end)
669+
670+
it('at the end',function()
671+
feed('<C-R>r')
672+
screen:expect([[
673+
{7: 1 } |
674+
{7: 2 } |
675+
{7: 3 } |
676+
{7: 4 } |
677+
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
678+
{7: 6 }:aaaaaaaa {1: } |
679+
{3:-- TERMINAL --} |
680+
]])
681+
eq(':aaaaaaaa',eval('nvim_get_current_line()'))
682+
eq({6,13},eval('nvim_win_get_cursor(0)'))
683+
feed([[<C-\><C-N>]])
684+
screen:expect([[
685+
{7: 1 } |
686+
{7: 2 } |
687+
{7: 3 } |
688+
{7: 4 } |
689+
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
690+
{7: 6 }:aaaaaaaa ^ {2: } |
691+
|
692+
]])
693+
eq({6,12},eval('nvim_win_get_cursor(0)'))
694+
end)
695+
end)
696+
633697
describe('in a line with single-cell multibyte characters and no trailing spaces,',function()
634698
before_each(function()
635699
setup_ex_register('µµµµµµµµ')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp