fix(suggestion): fixes re-rendering logic (#4380)

This commit is contained in:
Francisco Vergara 2024-06-12 01:30:55 -04:00 committed by GitHub
parent 4e4c622e1b
commit 8d93070bbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -99,7 +99,7 @@ export interface SuggestionOptions<I = any, TSelected = any> {
* @param props The props object. * @param props The props object.
* @returns {boolean} * @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 findSuggestionMatch?: typeof defaultFindSuggestionMatch
} }
@ -194,9 +194,10 @@ export function Suggestion<I = any, TSelected = any>({
const started = !prev.active && next.active const started = !prev.active && next.active
const stopped = prev.active && !next.active const stopped = prev.active && !next.active
const changed = !started && !stopped && prev.query !== next.query const changed = !started && !stopped && prev.query !== next.query
const handleStart = started || moved
const handleChange = changed && !moved const handleStart = started
const handleExit = stopped || moved const handleChange = changed || moved
const handleExit = stopped
// Cancel when suggestion isn't active // Cancel when suggestion isn't active
if (!handleStart && !handleChange && !handleExit) { if (!handleStart && !handleChange && !handleExit) {
@ -329,7 +330,9 @@ export function Suggestion<I = any, TSelected = any>({
const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}` const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`
// If we found a match, update the current state to show it // 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.active = true
next.decorationId = prev.decorationId ? prev.decorationId : decorationId next.decorationId = prev.decorationId ? prev.decorationId : decorationId
next.range = match.range next.range = match.range