Skip to content

Commit 84a9308

Browse files
committed
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)
1 parent 600323b commit 84a9308

File tree

3 files changed

+37
-54
lines changed

3 files changed

+37
-54
lines changed

src/buffer.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int buf_same_ino(buf_T *buf, stat_T *stp);
3838
static int otherfile_buf(buf_T *buf, char_u *ffname);
3939
#endif
4040
#ifdef FEAT_TITLE
41-
static int ti_change(char_u *str, char_u **last);
41+
static int value_changed(char_u *str, char_u **last);
4242
#endif
4343
static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file);
4444
static void free_buffer(buf_T *);
@@ -3545,20 +3545,18 @@ col_print(
35453545
}
35463546

35473547
#if defined(FEAT_TITLE) || defined(PROTO)
3548-
/*
3549-
* put file name in title bar of window and in icon title
3550-
*/
3551-
35523548
static char_u *lasttitle = NULL;
35533549
static char_u *lasticon = NULL;
35543550

3551+
/*
3552+
* Put the file name in the title bar and icon of the window.
3553+
*/
35553554
void
35563555
maketitle(void)
35573556
{
35583557
char_u *p;
3559-
char_u *t_str = NULL;
3560-
char_u *i_name;
3561-
char_u *i_str = NULL;
3558+
char_u *title_str = NULL;
3559+
char_u *icon_str = NULL;
35623560
int maxlen = 0;
35633561
int len;
35643562
int mustset;
@@ -3574,7 +3572,7 @@ maketitle(void)
35743572

35753573
need_maketitle = FALSE;
35763574
if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL)
3577-
return;
3575+
return; // nothing to do
35783576

35793577
if (p_title)
35803578
{
@@ -3585,7 +3583,7 @@ maketitle(void)
35853583
maxlen = 10;
35863584
}
35873585

3588-
t_str = buf;
3586+
title_str = buf;
35893587
if (*p_titlestring != NUL)
35903588
{
35913589
#ifdef FEAT_STL_OPT
@@ -3598,7 +3596,7 @@ maketitle(void)
35983596
use_sandbox = was_set_insecurely((char_u *)"titlestring", 0);
35993597
# endif
36003598
called_emsg = FALSE;
3601-
build_stl_str_hl(curwin, t_str, sizeof(buf),
3599+
build_stl_str_hl(curwin, title_str, sizeof(buf),
36023600
p_titlestring, use_sandbox,
36033601
0, maxlen, NULL, NULL);
36043602
if (called_emsg)
@@ -3608,7 +3606,7 @@ maketitle(void)
36083606
}
36093607
else
36103608
#endif
3611-
t_str = p_titlestring;
3609+
title_str = p_titlestring;
36123610
}
36133611
else
36143612
{
@@ -3714,11 +3712,11 @@ maketitle(void)
37143712
}
37153713
}
37163714
}
3717-
mustset = ti_change(t_str, &lasttitle);
3715+
mustset = value_changed(title_str, &lasttitle);
37183716

37193717
if (p_icon)
37203718
{
3721-
i_str = buf;
3719+
icon_str = buf;
37223720
if (*p_iconstring != NUL)
37233721
{
37243722
#ifdef FEAT_STL_OPT
@@ -3731,7 +3729,7 @@ maketitle(void)
37313729
use_sandbox = was_set_insecurely((char_u *)"iconstring", 0);
37323730
# endif
37333731
called_emsg = FALSE;
3734-
build_stl_str_hl(curwin, i_str, sizeof(buf),
3732+
build_stl_str_hl(curwin, icon_str, sizeof(buf),
37353733
p_iconstring, use_sandbox,
37363734
0, 0, NULL, NULL);
37373735
if (called_emsg)
@@ -3741,32 +3739,32 @@ maketitle(void)
37413739
}
37423740
else
37433741
#endif
3744-
i_str = p_iconstring;
3742+
icon_str = p_iconstring;
37453743
}
37463744
else
37473745
{
37483746
if (buf_spname(curbuf) != NULL)
3749-
i_name = buf_spname(curbuf);
3747+
p = buf_spname(curbuf);
37503748
else /* use file name only in icon */
3751-
i_name = gettail(curbuf->b_ffname);
3752-
*i_str = NUL;
3749+
p = gettail(curbuf->b_ffname);
3750+
*icon_str = NUL;
37533751
/* Truncate name at 100 bytes. */
3754-
len = (int)STRLEN(i_name);
3752+
len = (int)STRLEN(p);
37553753
if (len > 100)
37563754
{
37573755
len -= 100;
37583756
#ifdef FEAT_MBYTE
37593757
if (has_mbyte)
3760-
len += (*mb_tail_off)(i_name, i_name + len) + 1;
3758+
len += (*mb_tail_off)(p, p + len) + 1;
37613759
#endif
3762-
i_name += len;
3760+
p += len;
37633761
}
3764-
STRCPY(i_str, i_name);
3765-
trans_characters(i_str, IOSIZE);
3762+
STRCPY(icon_str, p);
3763+
trans_characters(icon_str, IOSIZE);
37663764
}
37673765
}
37683766

3769-
mustset |= ti_change(i_str, &lasticon);
3767+
mustset |= value_changed(icon_str, &lasticon);
37703768

37713769
if (mustset)
37723770
resettitle();
@@ -3775,20 +3773,25 @@ maketitle(void)
37753773
/*
37763774
* Used for title and icon: Check if "str" differs from "*last". Set "*last"
37773775
* from "str" if it does.
3778-
* Return TRUE when "*last" changed.
3776+
* Return TRUE if resettitle() is to be called.
37793777
*/
37803778
static int
3781-
ti_change(char_u *str, char_u **last)
3779+
value_changed(char_u *str, char_u **last)
37823780
{
37833781
if ((str == NULL) != (*last == NULL)
37843782
|| (str != NULL && *last != NULL && STRCMP(str, *last) != 0))
37853783
{
37863784
vim_free(*last);
37873785
if (str == NULL)
3786+
{
37883787
*last = NULL;
3788+
mch_restore_title(last == &lasttitle ? 1 : 2);
3789+
}
37893790
else
3791+
{
37903792
*last = vim_strsave(str);
3791-
return TRUE;
3793+
return TRUE;
3794+
}
37923795
}
37933796
return FALSE;
37943797
}

src/option.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,9 +3256,6 @@ static char_u *illegal_char(char_u *, int);
32563256
#ifdef FEAT_CMDWIN
32573257
static char_u *check_cedit(void);
32583258
#endif
3259-
#ifdef FEAT_TITLE
3260-
static void did_set_title(int icon);
3261-
#endif
32623259
static char_u *option_expand(int opt_idx, char_u *val);
32633260
static void didset_options(void);
32643261
static void didset_options2(void);
@@ -5374,27 +5371,14 @@ check_cedit(void)
53745371
* the old value back.
53755372
*/
53765373
static void
5377-
did_set_title(
5378-
int icon) /* Did set icon instead of title */
5374+
did_set_title(void)
53795375
{
53805376
if (starting != NO_SCREEN
53815377
#ifdef FEAT_GUI
53825378
&& !gui.starting
53835379
#endif
53845380
)
5385-
{
53865381
maketitle();
5387-
if (icon)
5388-
{
5389-
if (!p_icon)
5390-
mch_restore_title(2);
5391-
}
5392-
else
5393-
{
5394-
if (!p_title)
5395-
mch_restore_title(1);
5396-
}
5397-
}
53985382
}
53995383
#endif
54005384

@@ -6949,8 +6933,7 @@ did_set_string_option(
69496933
else
69506934
stl_syntax &= ~flagval;
69516935
# endif
6952-
did_set_title(varp == &p_iconstring);
6953-
6936+
did_set_title();
69546937
}
69556938
#endif
69566939

@@ -8401,14 +8384,9 @@ set_bool_option(
84018384

84028385
#ifdef FEAT_TITLE
84038386
/* when 'title' changed, may need to change the title; same for 'icon' */
8404-
else if ((int *)varp == &p_title)
8405-
{
8406-
did_set_title(FALSE);
8407-
}
8408-
8409-
else if ((int *)varp == &p_icon)
8387+
else if ((int *)varp == &p_title || (int *)varp == &p_icon)
84108388
{
8411-
did_set_title(TRUE);
8389+
did_set_title();
84128390
}
84138391
#endif
84148392

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
61,
764766
/**/
765767
60,
766768
/**/

0 commit comments

Comments
 (0)