fix(editor): 更多菜单收纳项展示文案并去掉悬浮提示

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
roymondchen 2026-12-01 16:09:29 +08:00
parent d068b7c1c4
commit ab9fb263ee
2 changed files with 68 additions and 1 deletions

View File

@ -112,10 +112,17 @@ const hiddenIndexSet = ref<Set<number>>(new Set());
const hasOverflow = computed(() => hiddenIndexSet.value.size > 0);
// 更多菜单是纵向列表:分割线改成横线;收进去的首尾分割线没有分组意义,直接去掉。
// 收进去的项统一展示文案:有 text 用 text,没有则用 tooltip,不再挂悬浮提示。
const overflowItems = computed(() => {
const items = props.items
.filter((_, index) => hiddenIndexSet.value.has(index))
.map((item) => (item.type === 'divider' ? { ...item, direction: 'horizontal' as const } : item));
.map((item) => {
if (item.type === 'divider') {
return { ...item, direction: 'horizontal' as const };
}
if (item.type === 'component') return item;
return { ...item, text: item.text || item.tooltip, tooltip: undefined };
});
let start = 0;
let end = items.length;

View File

@ -23,6 +23,7 @@ vi.mock('@editor/components/ToolButton.vue', () => ({
ref: rootEl,
class: ['tool-btn', (props.data as any)?.className, (props.data as any)?.type],
'data-direction': (props.data as any)?.direction || '',
'data-tooltip': (props.data as any)?.tooltip || '',
},
(props.data as any)?.text || '',
);
@ -415,6 +416,65 @@ describe('NavMenuColumn', () => {
wrapper.unmount();
});
test('更多菜单有 text 时展示 text,没有 text 时展示 tooltip', async () => {
const items = [
{ type: 'button', text: 'A' },
{ type: 'button', className: 'save', text: '保存', tooltip: '保存到本地' },
{ type: 'button', className: 'src', tooltip: '源码' },
];
const wrapper = mount(NavMenuColumn as any, {
props: { columnKey: 'right', items, width: 80 },
attachTo: document.body,
});
const columnEl = wrapper.find('.m-editor-nav-menu-column').element as HTMLElement;
Object.defineProperty(columnEl, 'clientWidth', { configurable: true, get: () => 80 });
const moreEl = wrapper.find('.m-editor-nav-menu-more-wrapper').element as HTMLElement;
moreEl.getBoundingClientRect = () => ({
width: 30,
height: 0,
top: 0,
left: 0,
right: 0,
bottom: 0,
x: 0,
y: 0,
toJSON: () => ({}),
});
wrapper.findAll('.tool-btn').forEach((b) => {
const el = b.element as HTMLElement;
el.getBoundingClientRect = () => ({
width: 40,
height: 0,
top: 0,
left: 0,
right: 0,
bottom: 0,
x: 0,
y: 0,
toJSON: () => ({}),
});
});
roCallbacks.forEach((cb) => cb());
await flushRaf();
await flushRaf();
const overflow = wrapper.find('.m-editor-nav-menu-overflow-list');
expect(overflow.find('.save').text()).toBe('保存');
expect(overflow.find('.save').attributes('data-tooltip')).toBe('');
expect(overflow.find('.src').text()).toBe('源码');
expect(overflow.find('.src').attributes('data-tooltip')).toBe('');
expect(wrapper.find('.m-editor-nav-menu-column > .save').attributes('data-tooltip')).toBe('保存到本地');
expect(wrapper.find('.m-editor-nav-menu-column > .src').attributes('data-tooltip')).toBe('源码');
wrapper.unmount();
});
test('更多菜单首尾的分割线会被去掉,中间的分割线保留', async () => {
const items = [
{ type: 'button', text: 'A' },