Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SuggestionPlugin support Composition event #1295

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions packages/core/src/extensions/SuggestionMenu/SuggestionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ const suggestionMenuPluginKey = new PluginKey("SuggestionMenuPlugin");
* - This version hides some unnecessary complexity from the user of the plugin.
* - This version handles key events differently
*/
let _isComposing = false;
let _compositionEndFlag = false;
export class SuggestionMenuProseMirrorPlugin<
BSchema extends BlockSchema,
I extends InlineContentSchema,
Expand Down Expand Up @@ -243,7 +245,8 @@ export class SuggestionMenuProseMirrorPlugin<
// Checks if the menu should be hidden.
if (
// Highlighting text should hide the menu.
newState.selection.from !== newState.selection.to ||
// In safari,when in composition event,this condition will match.
(!_isComposing && newState.selection.from !== newState.selection.to) ||
// Transactions with plugin metadata should hide the menu.
suggestionPluginTransactionMeta === null ||
// Certain mouse events should hide the menu.
Expand All @@ -261,16 +264,40 @@ export class SuggestionMenuProseMirrorPlugin<
const next = { ...prev };

// Updates the current query.
next.query = newState.doc.textBetween(
prev.queryStartPos!,
newState.selection.from
);
if(_compositionEndFlag){
_compositionEndFlag = false
next.query = newState.doc.textBetween(
prev.queryStartPos!,
newState.selection.from
);
return next;
}
if(!_isComposing)
{
next.query = newState.doc.textBetween(
prev.queryStartPos!,
newState.selection.from
);
return next;
}

return next;
},
},

props: {
handleDOMEvents:{
compositionstart:()=>{
_isComposing = true;
return false;
},
compositionend:(view)=>{
_isComposing = false;
_compositionEndFlag = true;
view.dispatch(view.state.tr.setMeta("isComposing", false));
return false;
}
},
handleTextInput(view, _from, _to, text) {
const suggestionPluginState: SuggestionPluginState = (
this as Plugin
Expand Down