mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
Auto-wrap desktop session tabs to a second row on overflow
When desktop session tabs overflow one row, wrap them to a second row instead of horizontal scroll — unless the user has pinned the manual two-row layout (tabTwoRows). Mobile/tablet keep horizontal scroll. The wrap policy (shouldAutoWrapTabs) lives in constants.js as a pure, unit-testable function; updateTabOverflowMode() measures overflow after each tab render and toggles .tabs-auto-wrap. Test: test/tab-overflow.test.ts (vm-loads constants.js, asserts the policy).
This commit is contained in:
@@ -2656,6 +2656,39 @@ class CodemanApp {
|
||||
this._fullRenderSessionTabs();
|
||||
}
|
||||
|
||||
this.updateTabOverflowMode();
|
||||
}
|
||||
|
||||
// Auto-wrap desktop session tabs to a second row when they overflow one row,
|
||||
// unless the user has pinned the manual two-row layout (tabTwoRows). Mobile/
|
||||
// tablet keep horizontal scroll. Policy lives in constants.js for unit testing.
|
||||
updateTabOverflowMode() {
|
||||
const container = this.$('sessionTabs');
|
||||
if (!container) return;
|
||||
|
||||
const deviceType = MobileDetection.getDeviceType();
|
||||
const settings = this.loadAppSettingsFromStorage();
|
||||
const defaults = this.getDefaultSettings();
|
||||
const manualTwoRows = deviceType === 'desktop' ? (settings.tabTwoRows ?? defaults.tabTwoRows ?? false) : false;
|
||||
|
||||
if (manualTwoRows || deviceType !== 'desktop') {
|
||||
container.classList.remove('tabs-auto-wrap');
|
||||
return;
|
||||
}
|
||||
|
||||
// Measure the natural one-row overflow, then enable wrapping only if needed.
|
||||
container.classList.remove('tabs-auto-wrap');
|
||||
const shouldWrap = window.CodemanTabOverflow?.shouldAutoWrapTabs
|
||||
? window.CodemanTabOverflow.shouldAutoWrapTabs({
|
||||
deviceType,
|
||||
manualTwoRows,
|
||||
tabCount: this.sessions.size,
|
||||
scrollWidth: container.scrollWidth,
|
||||
clientWidth: container.clientWidth,
|
||||
})
|
||||
: container.scrollWidth > container.clientWidth + 1;
|
||||
|
||||
container.classList.toggle('tabs-auto-wrap', shouldWrap);
|
||||
}
|
||||
|
||||
_fullRenderSessionTabs() {
|
||||
|
||||
@@ -114,9 +114,24 @@ function evaluateWebGLLongTaskTrip(recent, entries, now, config = WEBGL_FALLBACK
|
||||
// Expose for tests. `const` declarations at the top of a non-module script
|
||||
// are global lexical bindings but not `window` properties, so explicit
|
||||
// assignment is the test-visible API surface.
|
||||
// Desktop tab-overflow policy: auto-wrap the session tabs to a second row when
|
||||
// they overflow one row (and the user hasn't pinned the manual two-row layout).
|
||||
function shouldAutoWrapTabs(input) {
|
||||
if (!input || input.deviceType !== 'desktop') return false;
|
||||
if (input.manualTwoRows) return false;
|
||||
if ((input.tabCount || 0) < 2) return false;
|
||||
|
||||
const scrollWidth = Number(input.scrollWidth) || 0;
|
||||
const clientWidth = Number(input.clientWidth) || 0;
|
||||
return scrollWidth > clientWidth + 1;
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.WEBGL_FALLBACK = WEBGL_FALLBACK;
|
||||
window.evaluateWebGLLongTaskTrip = evaluateWebGLLongTaskTrip;
|
||||
window.CodemanTabOverflow = {
|
||||
shouldAutoWrapTabs,
|
||||
};
|
||||
}
|
||||
|
||||
// Scheduler API — prioritize terminal writes over background UI updates.
|
||||
|
||||
@@ -312,6 +312,13 @@ body {
|
||||
max-height: 120px;
|
||||
}
|
||||
|
||||
.session-tabs.tabs-auto-wrap {
|
||||
flex-wrap: wrap;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
max-height: 96px;
|
||||
}
|
||||
|
||||
.session-tabs::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
height: 0;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import vm from 'node:vm';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
function loadTabOverflowHelper() {
|
||||
const context = vm.createContext({ window: {}, globalThis: {} });
|
||||
const source = readFileSync(resolve(import.meta.dirname, '../src/web/public/constants.js'), 'utf8');
|
||||
vm.runInContext(source, context, { filename: 'constants.js' });
|
||||
return (context.window as { CodemanTabOverflow: { shouldAutoWrapTabs: (input: unknown) => boolean } })
|
||||
.CodemanTabOverflow;
|
||||
}
|
||||
|
||||
describe('tab overflow layout policy', () => {
|
||||
it('auto-wraps desktop tabs when their rendered width exceeds available tab space', () => {
|
||||
const helper = loadTabOverflowHelper();
|
||||
|
||||
expect(
|
||||
helper.shouldAutoWrapTabs({
|
||||
deviceType: 'desktop',
|
||||
manualTwoRows: false,
|
||||
tabCount: 18,
|
||||
scrollWidth: 1400,
|
||||
clientWidth: 760,
|
||||
})
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('does not auto-wrap when manual tall tabs are enabled or on mobile/tablet', () => {
|
||||
const helper = loadTabOverflowHelper();
|
||||
|
||||
expect(
|
||||
helper.shouldAutoWrapTabs({
|
||||
deviceType: 'desktop',
|
||||
manualTwoRows: true,
|
||||
tabCount: 18,
|
||||
scrollWidth: 1400,
|
||||
clientWidth: 760,
|
||||
})
|
||||
).toBe(false);
|
||||
expect(
|
||||
helper.shouldAutoWrapTabs({
|
||||
deviceType: 'mobile',
|
||||
manualTwoRows: false,
|
||||
tabCount: 18,
|
||||
scrollWidth: 1400,
|
||||
clientWidth: 320,
|
||||
})
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user