fix: keep New note in the magic notes page header

This commit is contained in:
mesalogo
2026-10-01 01:31:43 +08:00
parent d2ceff8db5
commit 0a02a17cb6
6 changed files with 44 additions and 30 deletions
+10 -1
View File
@@ -518,7 +518,11 @@ describe('MagicNotesWorkspace overview navigation', () => {
expect(css).toMatch(/\.magic-notes-page #magic-library-switch\s*\{[^}]*flex: 0 0 auto/)
expect(css).toMatch(/\.magic-notes-page #magic-library-switch\s*\{[^}]*width: fit-content/)
const switchButton = screen.getByRole('button', { name: '切换到待办' })
expect(screen.getByRole('region', { name: '笔记列表' })).toContainElement(screen.getByRole('button', { name: '新建笔记' }))
// New note sits in the page header, directly after the library switch; the list heading has no + button.
const newNoteButton = screen.getByRole('button', { name: '新建笔记' })
expect(newNoteButton.closest('.page-header__actions')).not.toBeNull()
expect(switchButton.nextElementSibling).toBe(newNoteButton)
expect(container.querySelector('#magic-library-panel-notes .magic-notes-pane-heading .icon-button')).toBeNull()
expect(switchButton.querySelector('.lucide-list-todo')).toBeInTheDocument()
switchButton.focus()
fireEvent.click(switchButton)
@@ -527,6 +531,7 @@ describe('MagicNotesWorkspace overview navigation', () => {
expect(screen.getByRole('region', { name: '待办列表' })).toBeVisible()
expect(container.querySelector('.magic-notes-layout')).not.toHaveClass('magic-notes-layout--detail')
expect(screen.queryByRole('tabpanel')).not.toBeInTheDocument()
expect(switchButton.nextElementSibling).toBe(screen.getByRole('button', { name: '新建笔记' }))
await waitFor(() => expect(switchButton).toHaveFocus())
fireEvent.click(switchButton)
expect(screen.getByRole('button', { name: '切换到待办' })).toBe(switchButton)
@@ -554,6 +559,10 @@ describe('MagicNotesWorkspace overview navigation', () => {
expect(screen.getByRole('separator', { name: '调整笔记列表宽度' })).toBeVisible()
// Back to overview lives in the page header's top-right actions while a note is open.
expect(screen.getByRole('button', { name: '返回总览' }).closest('.page-header__actions')).not.toBeNull()
expect(screen.getByRole('button', { name: '返回总览' }).nextElementSibling).toBe(screen.getByRole('button', { name: '新建笔记' }))
fireEvent.click(screen.getByRole('button', { name: '新建笔记' }))
expect(within(overview).getByLabelText('笔记标题')).toBeVisible()
fireEvent.click(within(overview).getByRole('button', { name: '取消' }))
expect(screen.queryByRole('button', { name: '切换到待办' })).not.toBeInTheDocument()
expect(screen.getByRole('searchbox')).toBeVisible()
expect(screen.getByRole('button', { name: '新建笔记' })).toBeVisible()
+18 -19
View File
@@ -2178,22 +2178,26 @@ export function MagicNotesWorkspace({
{libraryView === 'notes' ? <ListTodo aria-hidden="true" size={15} /> : <BookOpen aria-hidden="true" size={15} />}
{t(libraryView === 'notes' ? 'actions.switchToTodos' : 'actions.switchToNotes')}
</button>
{libraryView === 'todos' && <button
id="magic-note-new"
className="primary-button"
disabled={Boolean(busy)}
type="button"
onClick={() => {
setValidation(undefined)
setLibraryView('notes')
setCreating(true)
}}
>
<Plus aria-hidden="true" size={15} />
{t('actions.newNote')}
</button>}
</>
)}
<button
id="magic-note-new"
className="primary-button"
disabled={Boolean(busy)}
type="button"
onClick={() => {
setValidation(undefined)
setLibraryView('notes')
setCreating(true)
if (detailView) {
if (isNarrowWorkspace) void requestDraftSwitch({ kind: 'overview' })
else setNotesPaneOpen(true)
}
}}
>
<Plus aria-hidden="true" size={15} />
{t('actions.newNote')}
</button>
</>
}
help={t('page.description')}
@@ -2265,11 +2269,6 @@ export function MagicNotesWorkspace({
disabled={Boolean(busy)}
onClick={() => setTagManagerOpen(true)}
/>
<button id="magic-note-new" type="button" className="icon-button"
disabled={Boolean(busy)} aria-label={t('actions.newNote')} title={t('actions.newNote')}
onClick={() => { setValidation(undefined); setCreating(true) }}>
<Plus size={15} />
</button>
</div>
<label className="magic-notes-search">
<span className="sr-only">{t('notes.searchLabel')}</span>
+1 -6
View File
@@ -1408,21 +1408,16 @@
.magic-note-list-item[aria-current='true'] { border-color: Highlight; }
}
/* Heading: title and count grouped left, new-note action right. */
/* Heading: title and count grouped left, tag management right. New note lives in the page header. */
#magic-library-panel-notes > .magic-notes-pane-heading {
justify-content: flex-start;
gap: var(--space-2);
}
#magic-library-panel-notes > .magic-notes-pane-heading > .icon-button,
#magic-library-panel-notes > .magic-notes-pane-heading > #magic-note-tag-manager {
margin-left: auto;
}
#magic-library-panel-notes > .magic-notes-pane-heading > #magic-note-tag-manager + .icon-button {
margin-left: var(--space-1);
}
.magic-note-tag-manager-button {
min-height: 28px;
margin-block: -4px;