Compare commits

...

3 Commits

Author SHA1 Message Date
LemonBoy
d2a4662430 patch 8.2.4852: ANSI color index to RGB value not correct
Problem:    ANSI color index to RGB value not correct.
Solution:   Convert the cterm index to ANSI index. (closes #10321,
            closes #9836))
2022-05-01 17:43:33 +01:00
Bram Moolenaar
b4011afe53 patch 8.2.4851: compiler warning for uninitialized variable
Problem:    Compiler warning for uninitialized variable.
Solution:   Use another variable to decide to restore option values.
2022-05-01 00:42:24 +01:00
LemonBoy
d7c9564d8d patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Problem:    Mksession mixes up "tabpages" and "curdir" arguments.
Solution:   Correct logic for storing tabpage in session. (closes #10312)
2022-04-30 16:10:27 +01:00
4 changed files with 92 additions and 43 deletions

View File

@@ -620,16 +620,17 @@ makeopens(
int only_save_windows = TRUE;
int nr;
int restore_size = TRUE;
int restore_height_width = FALSE;
win_T *wp;
char_u *sname;
win_T *edited_win = NULL;
int tabnr;
int restore_stal = FALSE;
win_T *tab_firstwin;
frame_T *tab_topframe;
int cur_arg_idx = 0;
int next_arg_idx = 0;
int ret = FAIL;
tabpage_T *tp;
#ifdef FEAT_TERMINAL
hashtab_T terminal_bufs;
@@ -755,18 +756,11 @@ makeopens(
restore_stal = TRUE;
}
// May repeat putting Windows for each tab, when "tabpages" is in
// 'sessionoptions'.
// Don't use goto_tabpage(), it may change directory and trigger
// autocommands.
tab_firstwin = firstwin; // first window in tab page "tabnr"
tab_topframe = topframe;
if ((ssop_flags & SSOP_TABPAGES))
{
tabpage_T *tp;
// Similar to ses_win_rec() below, populate the tab pages first so
// later local options won't be copied to the new tabs.
// "tabpages" is in 'sessionoptions': Similar to ses_win_rec() below,
// populate the tab pages first so later local options won't be copied
// to the new tabs.
FOR_ALL_TABPAGES(tp)
// Use `bufhidden=wipe` to remove empty "placeholder" buffers once
// they are not needed. This prevents creating extra buffers (see
@@ -777,18 +771,20 @@ makeopens(
if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL)
goto fail;
}
for (tabnr = 1; ; ++tabnr)
// Assume "tabpages" is in 'sessionoptions'. If not then we only do
// "curtab" and bail out of the loop.
FOR_ALL_TABPAGES(tp)
{
tabpage_T *tp = NULL;
int need_tabnext = FALSE;
int cnr = 1;
// May repeat putting Windows for each tab, when "tabpages" is in
// 'sessionoptions'.
// Don't use goto_tabpage(), it may change directory and trigger
// autocommands.
if ((ssop_flags & SSOP_TABPAGES))
{
tp = find_tabpage(tabnr);
if (tp == NULL)
break; // done all tab pages
if (tp == curtab)
{
tab_firstwin = firstwin;
@@ -799,9 +795,15 @@ makeopens(
tab_firstwin = tp->tp_firstwin;
tab_topframe = tp->tp_topframe;
}
if (tabnr > 1)
if (tp != first_tabpage)
need_tabnext = TRUE;
}
else
{
tp = curtab;
tab_firstwin = firstwin;
tab_topframe = topframe;
}
// Before creating the window layout, try loading one file. If this
// is aborted we don't end up with a number of useless windows.
@@ -886,6 +888,7 @@ makeopens(
|| put_line(fd, "set winminwidth=0") == FAIL
|| put_line(fd, "set winwidth=1") == FAIL)
goto fail;
restore_height_width = TRUE;
}
if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL)
goto fail;
@@ -893,11 +896,11 @@ makeopens(
// Restore the tab-local working directory if specified
// Do this before the windows, so that the window-local directory can
// override the tab-local directory.
if (tp != NULL && tp->tp_localdir != NULL && ssop_flags & SSOP_CURDIR)
if ((ssop_flags & SSOP_CURDIR) && tp->tp_localdir != NULL)
{
if (fputs("tcd ", fd) < 0
|| ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL
|| put_eol(fd) == FAIL)
|| ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL
|| put_eol(fd) == FAIL)
goto fail;
did_lcd = TRUE;
}
@@ -978,7 +981,7 @@ makeopens(
goto fail;
}
if (tab_firstwin->w_next != NULL)
if (restore_height_width)
{
// Restore 'winminheight' and 'winminwidth'.
if (put_line(fd, "let &winminheight = s:save_winminheight") == FAIL

View File

@@ -6761,26 +6761,33 @@ static int grey_ramp[] = {
};
static char_u ansi_table[16][4] = {
// R G B idx
{ 0, 0, 0, 1}, // black
{224, 0, 0, 2}, // dark red
{ 0, 224, 0, 3}, // dark green
{224, 224, 0, 4}, // dark yellow / brown
{ 0, 0, 224, 5}, // dark blue
{224, 0, 224, 6}, // dark magenta
{ 0, 224, 224, 7}, // dark cyan
{224, 224, 224, 8}, // light grey
// R G B
{ 0, 0, 0}, // black
{224, 0, 0}, // dark red
{ 0, 224, 0}, // dark green
{224, 224, 0}, // dark yellow / brown
{ 0, 0, 224}, // dark blue
{224, 0, 224}, // dark magenta
{ 0, 224, 224}, // dark cyan
{224, 224, 224}, // light grey
{128, 128, 128, 9}, // dark grey
{255, 64, 64, 10}, // light red
{ 64, 255, 64, 11}, // light green
{255, 255, 64, 12}, // yellow
{ 64, 64, 255, 13}, // light blue
{255, 64, 255, 14}, // light magenta
{ 64, 255, 255, 15}, // light cyan
{255, 255, 255, 16}, // white
{128, 128, 128}, // dark grey
{255, 64, 64}, // light red
{ 64, 255, 64}, // light green
{255, 255, 64}, // yellow
{ 64, 64, 255}, // light blue
{255, 64, 255}, // light magenta
{ 64, 255, 255}, // light cyan
{255, 255, 255}, // white
};
#if defined(MSWIN)
// Mapping between cterm indices < 16 and their counterpart in the ANSI palette.
static const char_u cterm_ansi_idx[] = {
0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15
};
#endif
#define ANSI_INDEX_NONE 0
void
@@ -6790,10 +6797,15 @@ cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx)
if (nr < 16)
{
*r = ansi_table[nr][0];
*g = ansi_table[nr][1];
*b = ansi_table[nr][2];
*ansi_idx = ansi_table[nr][3];
#if defined(MSWIN)
idx = cterm_ansi_idx[nr];
#else
idx = nr;
#endif
*r = ansi_table[idx][0];
*g = ansi_table[idx][1];
*b = ansi_table[idx][2];
*ansi_idx = idx + 1;
}
else if (nr < 232)
{

View File

@@ -865,6 +865,34 @@ func Test_mksession_sesdir()
call delete('Xproj', 'rf')
endfunc
" Test for saving and restoring the tab-local working directory when there is
" only a single tab and 'tabpages' is not in 'sessionoptions'.
func Test_mksession_tcd_single_tabs()
only | tabonly
let save_cwd = getcwd()
set sessionoptions-=tabpages
set sessionoptions+=curdir
call mkdir('Xtopdir1')
call mkdir('Xtopdir2')
" There are two tab pages, the current one has local cwd set to 'Xtopdir2'.
exec 'tcd ' .. save_cwd .. '/Xtopdir1'
tabnew
exec 'tcd ' .. save_cwd .. '/Xtopdir2'
mksession! Xtest_tcd_single
source Xtest_tcd_single
call assert_equal(2, haslocaldir())
call assert_equal('Xtopdir2', fnamemodify(getcwd(-1, 0), ':t'))
%bwipe
set sessionoptions&
call chdir(save_cwd)
call delete('Xtopdir1', 'rf')
call delete('Xtopdir2', 'rf')
endfunc
" Test for storing the 'lines' and 'columns' settings
func Test_mksession_resize()
mksession! Xtest_mks1.out

View File

@@ -746,6 +746,12 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4852,
/**/
4851,
/**/
4850,
/**/
4849,
/**/