comparison src/session.c @ 28652:27dcbe70e1f0 v8.2.4850

patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments Commit: https://github.com/vim/vim/commit/d7c9564d8d24343f2e27205633032dd6ebe5232c Author: LemonBoy <thatlemon@gmail.com> Date: Sat Apr 30 16:10:27 2022 +0100 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 https://github.com/vim/vim/issues/10312)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 Apr 2022 17:15:02 +0200
parents 800e7de2f96d
children 8fc86c943863
comparison
equal deleted inserted replaced
28651:f3e46158f0dd 28652:27dcbe70e1f0
621 int nr; 621 int nr;
622 int restore_size = TRUE; 622 int restore_size = TRUE;
623 win_T *wp; 623 win_T *wp;
624 char_u *sname; 624 char_u *sname;
625 win_T *edited_win = NULL; 625 win_T *edited_win = NULL;
626 int tabnr;
627 int restore_stal = FALSE; 626 int restore_stal = FALSE;
628 win_T *tab_firstwin; 627 win_T *tab_firstwin;
629 frame_T *tab_topframe; 628 frame_T *tab_topframe;
630 int cur_arg_idx = 0; 629 int cur_arg_idx = 0;
631 int next_arg_idx = 0; 630 int next_arg_idx = 0;
632 int ret = FAIL; 631 int ret = FAIL;
632 tabpage_T *tp;
633 #ifdef FEAT_TERMINAL 633 #ifdef FEAT_TERMINAL
634 hashtab_T terminal_bufs; 634 hashtab_T terminal_bufs;
635 635
636 hash_init(&terminal_bufs); 636 hash_init(&terminal_bufs);
637 #endif 637 #endif
753 if (put_line(fd, "set stal=2") == FAIL) 753 if (put_line(fd, "set stal=2") == FAIL)
754 goto fail; 754 goto fail;
755 restore_stal = TRUE; 755 restore_stal = TRUE;
756 } 756 }
757 757
758 // May repeat putting Windows for each tab, when "tabpages" is in
759 // 'sessionoptions'.
760 // Don't use goto_tabpage(), it may change directory and trigger
761 // autocommands.
762 tab_firstwin = firstwin; // first window in tab page "tabnr"
763 tab_topframe = topframe;
764 if ((ssop_flags & SSOP_TABPAGES)) 758 if ((ssop_flags & SSOP_TABPAGES))
765 { 759 {
766 tabpage_T *tp; 760 // "tabpages" is in 'sessionoptions': Similar to ses_win_rec() below,
767 761 // populate the tab pages first so later local options won't be copied
768 // Similar to ses_win_rec() below, populate the tab pages first so 762 // to the new tabs.
769 // later local options won't be copied to the new tabs.
770 FOR_ALL_TABPAGES(tp) 763 FOR_ALL_TABPAGES(tp)
771 // Use `bufhidden=wipe` to remove empty "placeholder" buffers once 764 // Use `bufhidden=wipe` to remove empty "placeholder" buffers once
772 // they are not needed. This prevents creating extra buffers (see 765 // they are not needed. This prevents creating extra buffers (see
773 // cause of patch 8.1.0829) 766 // cause of patch 8.1.0829)
774 if (tp->tp_next != NULL 767 if (tp->tp_next != NULL
775 && put_line(fd, "tabnew +setlocal\\ bufhidden=wipe") == FAIL) 768 && put_line(fd, "tabnew +setlocal\\ bufhidden=wipe") == FAIL)
776 goto fail; 769 goto fail;
777 if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL) 770 if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL)
778 goto fail; 771 goto fail;
779 } 772 }
780 for (tabnr = 1; ; ++tabnr) 773
781 { 774 // Assume "tabpages" is in 'sessionoptions'. If not then we only do
782 tabpage_T *tp = NULL; 775 // "curtab" and bail out of the loop.
776 FOR_ALL_TABPAGES(tp)
777 {
783 int need_tabnext = FALSE; 778 int need_tabnext = FALSE;
784 int cnr = 1; 779 int cnr = 1;
785 780
781 // May repeat putting Windows for each tab, when "tabpages" is in
782 // 'sessionoptions'.
783 // Don't use goto_tabpage(), it may change directory and trigger
784 // autocommands.
786 if ((ssop_flags & SSOP_TABPAGES)) 785 if ((ssop_flags & SSOP_TABPAGES))
787 { 786 {
788 tp = find_tabpage(tabnr);
789
790 if (tp == NULL)
791 break; // done all tab pages
792 if (tp == curtab) 787 if (tp == curtab)
793 { 788 {
794 tab_firstwin = firstwin; 789 tab_firstwin = firstwin;
795 tab_topframe = topframe; 790 tab_topframe = topframe;
796 } 791 }
797 else 792 else
798 { 793 {
799 tab_firstwin = tp->tp_firstwin; 794 tab_firstwin = tp->tp_firstwin;
800 tab_topframe = tp->tp_topframe; 795 tab_topframe = tp->tp_topframe;
801 } 796 }
802 if (tabnr > 1) 797 if (tp != first_tabpage)
803 need_tabnext = TRUE; 798 need_tabnext = TRUE;
799 }
800 else
801 {
802 tp = curtab;
803 tab_firstwin = firstwin;
804 tab_topframe = topframe;
804 } 805 }
805 806
806 // Before creating the window layout, try loading one file. If this 807 // Before creating the window layout, try loading one file. If this
807 // is aborted we don't end up with a number of useless windows. 808 // is aborted we don't end up with a number of useless windows.
808 // This may have side effects! (e.g., compressed or network file). 809 // This may have side effects! (e.g., compressed or network file).
891 goto fail; 892 goto fail;
892 893
893 // Restore the tab-local working directory if specified 894 // Restore the tab-local working directory if specified
894 // Do this before the windows, so that the window-local directory can 895 // Do this before the windows, so that the window-local directory can
895 // override the tab-local directory. 896 // override the tab-local directory.
896 if (tp != NULL && tp->tp_localdir != NULL && ssop_flags & SSOP_CURDIR) 897 if ((ssop_flags & SSOP_CURDIR) && tp->tp_localdir != NULL)
897 { 898 {
898 if (fputs("tcd ", fd) < 0 899 if (fputs("tcd ", fd) < 0
899 || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL 900 || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL
900 || put_eol(fd) == FAIL) 901 || put_eol(fd) == FAIL)
901 goto fail; 902 goto fail;
902 did_lcd = TRUE; 903 did_lcd = TRUE;
903 } 904 }
904 905
905 // Restore the view of the window (options, file, cursor, etc.). 906 // Restore the view of the window (options, file, cursor, etc.).