@@ -764,32 +764,36 @@ - (void)selectTab:(int)index
764764
765765- (void )updateTabBar
766766{
767+ // Update the tab bar with the most up-to-date info, including number of
768+ // tabs and titles/tooltips. MacVim would also like to know which specific
769+ // tabs were moved/added/deleted in order for animation to work, but Vim
770+ // does not have specific callbacks to listen to that. Instead, since the
771+ // tabpage_T memory address is constant per tab, we use that as a permanent
772+ // identifier for each GUI tab so MacVim can do the association.
767773 NSMutableData *data = [NSMutableData data ];
768774
775+ // 1. Current selected tab index
769776 int idx = tabpage_index (curtab) - 1 ;
770777 [data appendBytes: &idx length: sizeof (int )];
771778
772779 tabpage_T *tp;
780+ // 2. Unique id for all the tabs
781+ // Do these first so they appear as a consecutive memory block.
773782 for (tp = first_tabpage; tp != NULL ; tp = tp->tp_next ) {
774- // Count the number of windows in the tabpage.
775- // win_T *wp = tp->tp_firstwin;
776- // int wincount;
777- // for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount);
778- // [data appendBytes:&wincount length:sizeof(int)];
779-
780- int tabProp = MMTabInfoCount;
781- [data appendBytes: &tabProp length: sizeof (int )];
782- for (tabProp = MMTabLabel; tabProp < MMTabInfoCount; ++tabProp) {
783+ [data appendBytes: &tp length: sizeof (void *)];
784+ }
785+ // Null terminate the unique IDs.
786+ tp = 0 ;
787+ [data appendBytes: &tp length: sizeof (void *)];
788+ // 3. Labels and tooltips of each tab
789+ for (tp = first_tabpage; tp != NULL ; tp = tp->tp_next ) {
790+ for (int tabProp = MMTabLabel; tabProp < MMTabInfoCount; ++tabProp) {
783791 // This function puts the label of the tab in the global 'NameBuff'.
784792 get_tabline_label (tp, (tabProp == MMTabToolTip));
785- NSString *s = [NSString stringWithVimString: NameBuff];
786- int len = [s lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
787- if (len < 0 )
788- len = 0 ;
789-
790- [data appendBytes: &len length: sizeof (int )];
793+ size_t len = STRLEN (NameBuff);
794+ [data appendBytes: &len length: sizeof (size_t )];
791795 if (len > 0 )
792- [data appendBytes: [s UTF8String ] length: len];
796+ [data appendBytes: NameBuff length: len];
793797 }
794798 }
795799
0 commit comments