mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-03 11:19:10 +08:00
Fix remaining notes bugs: breadcrumb root navigation and line break preservation
- Add root breadcrumb item for easy navigation back to notes home - Add onClearActiveFile callback to deselect active file when clicking root - Enable line breaks preservation in markdown (breaks: true) to fix forced line breaks when pasting text - Root breadcrumb now allows users to return to notes tree view Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>
This commit is contained in:
parent
6d259bb5bd
commit
d8bbd3fdb9
@ -16,7 +16,14 @@ import { menuItems } from './MenuConfig'
|
|||||||
|
|
||||||
const logger = loggerService.withContext('HeaderNavbar')
|
const logger = loggerService.withContext('HeaderNavbar')
|
||||||
|
|
||||||
const HeaderNavbar = ({ notesTree, getCurrentNoteContent, onToggleStar, onExpandPath, onRenameNode }) => {
|
const HeaderNavbar = ({
|
||||||
|
notesTree,
|
||||||
|
getCurrentNoteContent,
|
||||||
|
onToggleStar,
|
||||||
|
onExpandPath,
|
||||||
|
onRenameNode,
|
||||||
|
onClearActiveFile
|
||||||
|
}) => {
|
||||||
const { showWorkspace, toggleShowWorkspace } = useShowWorkspace()
|
const { showWorkspace, toggleShowWorkspace } = useShowWorkspace()
|
||||||
const { activeNode } = useActiveNode(notesTree)
|
const { activeNode } = useActiveNode(notesTree)
|
||||||
const [breadcrumbItems, setBreadcrumbItems] = useState<
|
const [breadcrumbItems, setBreadcrumbItems] = useState<
|
||||||
@ -54,11 +61,14 @@ const HeaderNavbar = ({ notesTree, getCurrentNoteContent, onToggleStar, onExpand
|
|||||||
|
|
||||||
const handleBreadcrumbClick = useCallback(
|
const handleBreadcrumbClick = useCallback(
|
||||||
(item: { treePath: string; isFolder: boolean }) => {
|
(item: { treePath: string; isFolder: boolean }) => {
|
||||||
if (item.isFolder && onExpandPath) {
|
if (item.treePath === '/' && onClearActiveFile) {
|
||||||
|
// Clicking root clears the active file and returns to tree view
|
||||||
|
onClearActiveFile()
|
||||||
|
} else if (item.isFolder && onExpandPath) {
|
||||||
onExpandPath(item.treePath)
|
onExpandPath(item.treePath)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[onExpandPath]
|
[onExpandPath, onClearActiveFile]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleTitleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleTitleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
@ -166,8 +176,18 @@ const HeaderNavbar = ({ notesTree, getCurrentNoteContent, onToggleStar, onExpand
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Add root directory as the first breadcrumb item if not already at root
|
||||||
|
if (pathParts.length > 0) {
|
||||||
|
items.unshift({
|
||||||
|
key: 'root',
|
||||||
|
title: t('notes.root_directory') || 'Notes',
|
||||||
|
treePath: '/',
|
||||||
|
isFolder: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setBreadcrumbItems(items)
|
setBreadcrumbItems(items)
|
||||||
}, [activeNode, notesTree])
|
}, [activeNode, notesTree, t])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavbarHeader
|
<NavbarHeader
|
||||||
|
|||||||
@ -777,6 +777,10 @@ const NotesPage: FC = () => {
|
|||||||
[notesTree, updateExpandedPaths]
|
[notesTree, updateExpandedPaths]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const handleClearActiveFile = useCallback(() => {
|
||||||
|
dispatch(setActiveFilePath(undefined))
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
const getCurrentNoteContent = useCallback(() => {
|
const getCurrentNoteContent = useCallback(() => {
|
||||||
if (settings.defaultEditMode === 'source') {
|
if (settings.defaultEditMode === 'source') {
|
||||||
return currentContent
|
return currentContent
|
||||||
@ -870,6 +874,7 @@ const NotesPage: FC = () => {
|
|||||||
onToggleStar={handleToggleStar}
|
onToggleStar={handleToggleStar}
|
||||||
onExpandPath={handleExpandPath}
|
onExpandPath={handleExpandPath}
|
||||||
onRenameNode={handleRenameNode}
|
onRenameNode={handleRenameNode}
|
||||||
|
onClearActiveFile={handleClearActiveFile}
|
||||||
/>
|
/>
|
||||||
<NotesEditor
|
<NotesEditor
|
||||||
activeNodeId={activeNode?.id}
|
activeNodeId={activeNode?.id}
|
||||||
|
|||||||
@ -81,7 +81,7 @@ export interface TaskListOptions {
|
|||||||
const md = new MarkdownIt({
|
const md = new MarkdownIt({
|
||||||
html: true, // Enable HTML tags in source
|
html: true, // Enable HTML tags in source
|
||||||
xhtmlOut: true, // Use '>' for single tags (<br> instead of <br />)
|
xhtmlOut: true, // Use '>' for single tags (<br> instead of <br />)
|
||||||
breaks: false,
|
breaks: true, // Preserve line breaks when pasting text
|
||||||
linkify: false, // Autoconvert URL-like text to links
|
linkify: false, // Autoconvert URL-like text to links
|
||||||
typographer: false // Enable smartypants and other sweet transforms
|
typographer: false // Enable smartypants and other sweet transforms
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user