0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.1.0061: window title is wrong after resetting and setting 'title'

Problem:    Window title is wrong after resetting and setting 'title'.
Solution:   Move resetting the title into maketitle(). (Jason Franklin)
This commit is contained in:
Bram Moolenaar
2018-06-16 22:58:15 +02:00
parent 600323b4ef
commit 84a9308511
3 changed files with 37 additions and 54 deletions

View File

@@ -38,7 +38,7 @@ static int buf_same_ino(buf_T *buf, stat_T *stp);
static int otherfile_buf(buf_T *buf, char_u *ffname); static int otherfile_buf(buf_T *buf, char_u *ffname);
#endif #endif
#ifdef FEAT_TITLE #ifdef FEAT_TITLE
static int ti_change(char_u *str, char_u **last); static int value_changed(char_u *str, char_u **last);
#endif #endif
static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file);
static void free_buffer(buf_T *); static void free_buffer(buf_T *);
@@ -3545,20 +3545,18 @@ col_print(
} }
#if defined(FEAT_TITLE) || defined(PROTO) #if defined(FEAT_TITLE) || defined(PROTO)
/*
* put file name in title bar of window and in icon title
*/
static char_u *lasttitle = NULL; static char_u *lasttitle = NULL;
static char_u *lasticon = NULL; static char_u *lasticon = NULL;
/*
* Put the file name in the title bar and icon of the window.
*/
void void
maketitle(void) maketitle(void)
{ {
char_u *p; char_u *p;
char_u *t_str = NULL; char_u *title_str = NULL;
char_u *i_name; char_u *icon_str = NULL;
char_u *i_str = NULL;
int maxlen = 0; int maxlen = 0;
int len; int len;
int mustset; int mustset;
@@ -3574,7 +3572,7 @@ maketitle(void)
need_maketitle = FALSE; need_maketitle = FALSE;
if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL) if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL)
return; return; // nothing to do
if (p_title) if (p_title)
{ {
@@ -3585,7 +3583,7 @@ maketitle(void)
maxlen = 10; maxlen = 10;
} }
t_str = buf; title_str = buf;
if (*p_titlestring != NUL) if (*p_titlestring != NUL)
{ {
#ifdef FEAT_STL_OPT #ifdef FEAT_STL_OPT
@@ -3598,7 +3596,7 @@ maketitle(void)
use_sandbox = was_set_insecurely((char_u *)"titlestring", 0); use_sandbox = was_set_insecurely((char_u *)"titlestring", 0);
# endif # endif
called_emsg = FALSE; called_emsg = FALSE;
build_stl_str_hl(curwin, t_str, sizeof(buf), build_stl_str_hl(curwin, title_str, sizeof(buf),
p_titlestring, use_sandbox, p_titlestring, use_sandbox,
0, maxlen, NULL, NULL); 0, maxlen, NULL, NULL);
if (called_emsg) if (called_emsg)
@@ -3608,7 +3606,7 @@ maketitle(void)
} }
else else
#endif #endif
t_str = p_titlestring; title_str = p_titlestring;
} }
else else
{ {
@@ -3714,11 +3712,11 @@ maketitle(void)
} }
} }
} }
mustset = ti_change(t_str, &lasttitle); mustset = value_changed(title_str, &lasttitle);
if (p_icon) if (p_icon)
{ {
i_str = buf; icon_str = buf;
if (*p_iconstring != NUL) if (*p_iconstring != NUL)
{ {
#ifdef FEAT_STL_OPT #ifdef FEAT_STL_OPT
@@ -3731,7 +3729,7 @@ maketitle(void)
use_sandbox = was_set_insecurely((char_u *)"iconstring", 0); use_sandbox = was_set_insecurely((char_u *)"iconstring", 0);
# endif # endif
called_emsg = FALSE; called_emsg = FALSE;
build_stl_str_hl(curwin, i_str, sizeof(buf), build_stl_str_hl(curwin, icon_str, sizeof(buf),
p_iconstring, use_sandbox, p_iconstring, use_sandbox,
0, 0, NULL, NULL); 0, 0, NULL, NULL);
if (called_emsg) if (called_emsg)
@@ -3741,32 +3739,32 @@ maketitle(void)
} }
else else
#endif #endif
i_str = p_iconstring; icon_str = p_iconstring;
} }
else else
{ {
if (buf_spname(curbuf) != NULL) if (buf_spname(curbuf) != NULL)
i_name = buf_spname(curbuf); p = buf_spname(curbuf);
else /* use file name only in icon */ else /* use file name only in icon */
i_name = gettail(curbuf->b_ffname); p = gettail(curbuf->b_ffname);
*i_str = NUL; *icon_str = NUL;
/* Truncate name at 100 bytes. */ /* Truncate name at 100 bytes. */
len = (int)STRLEN(i_name); len = (int)STRLEN(p);
if (len > 100) if (len > 100)
{ {
len -= 100; len -= 100;
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
if (has_mbyte) if (has_mbyte)
len += (*mb_tail_off)(i_name, i_name + len) + 1; len += (*mb_tail_off)(p, p + len) + 1;
#endif #endif
i_name += len; p += len;
} }
STRCPY(i_str, i_name); STRCPY(icon_str, p);
trans_characters(i_str, IOSIZE); trans_characters(icon_str, IOSIZE);
} }
} }
mustset |= ti_change(i_str, &lasticon); mustset |= value_changed(icon_str, &lasticon);
if (mustset) if (mustset)
resettitle(); resettitle();
@@ -3775,20 +3773,25 @@ maketitle(void)
/* /*
* Used for title and icon: Check if "str" differs from "*last". Set "*last" * Used for title and icon: Check if "str" differs from "*last". Set "*last"
* from "str" if it does. * from "str" if it does.
* Return TRUE when "*last" changed. * Return TRUE if resettitle() is to be called.
*/ */
static int static int
ti_change(char_u *str, char_u **last) value_changed(char_u *str, char_u **last)
{ {
if ((str == NULL) != (*last == NULL) if ((str == NULL) != (*last == NULL)
|| (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) || (str != NULL && *last != NULL && STRCMP(str, *last) != 0))
{ {
vim_free(*last); vim_free(*last);
if (str == NULL) if (str == NULL)
{
*last = NULL; *last = NULL;
mch_restore_title(last == &lasttitle ? 1 : 2);
}
else else
{
*last = vim_strsave(str); *last = vim_strsave(str);
return TRUE; return TRUE;
}
} }
return FALSE; return FALSE;
} }

View File

@@ -3256,9 +3256,6 @@ static char_u *illegal_char(char_u *, int);
#ifdef FEAT_CMDWIN #ifdef FEAT_CMDWIN
static char_u *check_cedit(void); static char_u *check_cedit(void);
#endif #endif
#ifdef FEAT_TITLE
static void did_set_title(int icon);
#endif
static char_u *option_expand(int opt_idx, char_u *val); static char_u *option_expand(int opt_idx, char_u *val);
static void didset_options(void); static void didset_options(void);
static void didset_options2(void); static void didset_options2(void);
@@ -5374,27 +5371,14 @@ check_cedit(void)
* the old value back. * the old value back.
*/ */
static void static void
did_set_title( did_set_title(void)
int icon) /* Did set icon instead of title */
{ {
if (starting != NO_SCREEN if (starting != NO_SCREEN
#ifdef FEAT_GUI #ifdef FEAT_GUI
&& !gui.starting && !gui.starting
#endif #endif
) )
{
maketitle(); maketitle();
if (icon)
{
if (!p_icon)
mch_restore_title(2);
}
else
{
if (!p_title)
mch_restore_title(1);
}
}
} }
#endif #endif
@@ -6949,8 +6933,7 @@ did_set_string_option(
else else
stl_syntax &= ~flagval; stl_syntax &= ~flagval;
# endif # endif
did_set_title(varp == &p_iconstring); did_set_title();
} }
#endif #endif
@@ -8401,14 +8384,9 @@ set_bool_option(
#ifdef FEAT_TITLE #ifdef FEAT_TITLE
/* when 'title' changed, may need to change the title; same for 'icon' */ /* when 'title' changed, may need to change the title; same for 'icon' */
else if ((int *)varp == &p_title) else if ((int *)varp == &p_title || (int *)varp == &p_icon)
{ {
did_set_title(FALSE); did_set_title();
}
else if ((int *)varp == &p_icon)
{
did_set_title(TRUE);
} }
#endif #endif

View File

@@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
61,
/**/ /**/
60, 60,
/**/ /**/