fix: note en double au retour et barre Gras/Italique à l’ouverture
Ne plus réinjecter une note déjà dans la liste, et n’afficher le menu de formatage que sur une vraie sélection de texte. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -61,8 +61,7 @@ import { applyClipRtlDirection } from '@/lib/editor/apply-clip-rtl-direction'
|
||||
import { NOTE_REQUEST_SAVE_EVENT } from '@/lib/note-change-sync'
|
||||
import { openNotePeek } from '@/lib/note-peek-sync'
|
||||
import { useAiConsent } from '@/components/legal/ai-consent-provider'
|
||||
import type { Editor } from '@tiptap/core'
|
||||
import type { EditorState } from '@tiptap/pm/state'
|
||||
import { isTextSelection, type Editor } from '@tiptap/core'
|
||||
import {
|
||||
Bold, Italic, Underline as UnderlineIcon, Strikethrough, Code,
|
||||
Heading1, Heading2, Heading3, List, ListOrdered, CheckSquare,
|
||||
@@ -75,7 +74,7 @@ import {
|
||||
} from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { toast } from 'sonner'
|
||||
import { NodeSelection } from '@tiptap/pm/state'
|
||||
import { AllSelection, NodeSelection } from '@tiptap/pm/state'
|
||||
|
||||
export interface RichTextEditorHandle {
|
||||
getEditor: () => Editor | null
|
||||
@@ -1403,17 +1402,25 @@ export const RichTextEditor = forwardRef<RichTextEditorHandle, RichTextEditorPro
|
||||
<BubbleMenu
|
||||
editor={editor}
|
||||
className="notion-bubble-menu"
|
||||
{...({
|
||||
tippyOptions: {
|
||||
appendTo: () => document.body,
|
||||
zIndex: 99999,
|
||||
fallbackPlacements: ['bottom', 'top']
|
||||
appendTo={() => document.body}
|
||||
shouldShow={({ editor: e, state, from, to, view, element }) => {
|
||||
if (!e.isEditable || e.isActive('codeBlock')) return false
|
||||
|
||||
const { selection } = state
|
||||
if (selection instanceof AllSelection) return false
|
||||
if (selection instanceof NodeSelection) {
|
||||
return selection.node.type.name === 'image'
|
||||
}
|
||||
} as any)}
|
||||
shouldShow={({ editor: e, state }: { editor: Editor; state: EditorState }) => {
|
||||
const { from, to } = state.selection
|
||||
const isImage = e.isActive('image')
|
||||
return (from !== to && !e.isActive('codeBlock')) || isImage
|
||||
if (!isTextSelection(selection) || selection.empty) return false
|
||||
|
||||
const selectedText = state.doc.textBetween(from, to)
|
||||
if (!selectedText.length) return false
|
||||
|
||||
// setContent à l’ouverture sélectionne parfois tout le document
|
||||
const docSize = state.doc.content.size
|
||||
if (docSize > 4 && from <= 1 && to >= docSize - 1) return false
|
||||
|
||||
return view.hasFocus() || element.contains(document.activeElement)
|
||||
}}
|
||||
>
|
||||
<BubbleToolbar editor={editor} onSuggestCharts={handleOpenChartSuggestions} />
|
||||
|
||||
Reference in New Issue
Block a user