mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
feat(editor): add reserveToolbarSpace option to enhance toolbar visibility management
This commit is contained in:
parent
0381632bc2
commit
a1d3356bf5
5 changed files with 36 additions and 4 deletions
|
|
@ -116,6 +116,7 @@ export function ReportPanelContent({
|
|||
const [exporting, setExporting] = useState<string | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const copyTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
const changeCountRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
|
@ -190,8 +191,21 @@ export function ReportPanelContent({
|
|||
useEffect(() => {
|
||||
setEditedMarkdown(null);
|
||||
setIsEditing(false);
|
||||
changeCountRef.current = 0;
|
||||
}, [activeReportId]);
|
||||
|
||||
const handleReportMarkdownChange = useCallback(
|
||||
(nextMarkdown: string) => {
|
||||
if (!isEditing) return;
|
||||
changeCountRef.current += 1;
|
||||
// Plate may emit an initial normalize/serialize change on mount.
|
||||
if (changeCountRef.current <= 1) return;
|
||||
const savedMarkdown = reportContent?.content ?? "";
|
||||
setEditedMarkdown(nextMarkdown === savedMarkdown ? null : nextMarkdown);
|
||||
},
|
||||
[isEditing, reportContent?.content]
|
||||
);
|
||||
|
||||
// Copy markdown content (uses latest editor content)
|
||||
const handleCopy = useCallback(async () => {
|
||||
if (!currentMarkdown) return;
|
||||
|
|
@ -299,6 +313,7 @@ export function ReportPanelContent({
|
|||
|
||||
const handleCancelEditing = useCallback(() => {
|
||||
setEditedMarkdown(null);
|
||||
changeCountRef.current = 0;
|
||||
setIsEditing(false);
|
||||
}, []);
|
||||
|
||||
|
|
@ -436,6 +451,7 @@ export function ReportPanelContent({
|
|||
className="size-6"
|
||||
onClick={() => {
|
||||
setEditedMarkdown(null);
|
||||
changeCountRef.current = 0;
|
||||
setIsEditing(true);
|
||||
}}
|
||||
>
|
||||
|
|
@ -473,11 +489,12 @@ export function ReportPanelContent({
|
|||
key={`report-${activeReportId}-${isEditing ? "editing" : "viewing"}`}
|
||||
preset="full"
|
||||
markdown={reportContent.content}
|
||||
onMarkdownChange={setEditedMarkdown}
|
||||
onMarkdownChange={handleReportMarkdownChange}
|
||||
readOnly={!isEditing}
|
||||
placeholder="Report content..."
|
||||
editorVariant="default"
|
||||
allowModeToggle={false}
|
||||
reserveToolbarSpace
|
||||
defaultEditing={isEditing}
|
||||
className="[&_[role=toolbar]]:!bg-sidebar"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue