* Calculate the display width of a tab
(tab: string, maxWidth?: number)
| 28 | * Calculate the display width of a tab |
| 29 | */ |
| 30 | function getTabWidth(tab: string, maxWidth?: number): number { |
| 31 | if (tab === ALL_TAB_LABEL) { |
| 32 | return ALL_TAB_LABEL.length + TAB_PADDING; |
| 33 | } |
| 34 | // For non-All tabs: " #{tag} " but truncate tag if needed |
| 35 | const tagWidth = stringWidth(tab); |
| 36 | const effectiveTagWidth = maxWidth ? Math.min(tagWidth, maxWidth - TAB_PADDING - HASH_PREFIX_LENGTH) : tagWidth; |
| 37 | return Math.max(0, effectiveTagWidth) + TAB_PADDING + HASH_PREFIX_LENGTH; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Truncate a tag to fit within maxWidth, accounting for padding and hash prefix |