mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 09:25:29 +08:00
fix(suggestion): fixes re-rendering logic (#4380)
This commit is contained in:
parent
4e4c622e1b
commit
8d93070bbe
@ -99,7 +99,7 @@ export interface SuggestionOptions<I = any, TSelected = any> {
|
||||
* @param props The props object.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
allow?: (props: { editor: Editor; state: EditorState; range: Range }) => boolean
|
||||
allow?: (props: { editor: Editor; state: EditorState; range: Range, isActive?: boolean }) => boolean
|
||||
findSuggestionMatch?: typeof defaultFindSuggestionMatch
|
||||
}
|
||||
|
||||
@ -194,9 +194,10 @@ export function Suggestion<I = any, TSelected = any>({
|
||||
const started = !prev.active && next.active
|
||||
const stopped = prev.active && !next.active
|
||||
const changed = !started && !stopped && prev.query !== next.query
|
||||
const handleStart = started || moved
|
||||
const handleChange = changed && !moved
|
||||
const handleExit = stopped || moved
|
||||
|
||||
const handleStart = started
|
||||
const handleChange = changed || moved
|
||||
const handleExit = stopped
|
||||
|
||||
// Cancel when suggestion isn't active
|
||||
if (!handleStart && !handleChange && !handleExit) {
|
||||
@ -329,7 +330,9 @@ export function Suggestion<I = any, TSelected = any>({
|
||||
const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`
|
||||
|
||||
// If we found a match, update the current state to show it
|
||||
if (match && allow({ editor, state, range: match.range })) {
|
||||
if (match && allow({
|
||||
editor, state, range: match.range, isActive: prev.active,
|
||||
})) {
|
||||
next.active = true
|
||||
next.decorationId = prev.decorationId ? prev.decorationId : decorationId
|
||||
next.range = match.range
|
||||
|
Loading…
Reference in New Issue
Block a user