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: highlight triggered while ime inputs are not committed #5

Open
wants to merge 1 commit 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
16 changes: 15 additions & 1 deletion SyntaxHighlightWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class HighlightCodeBlockWidget extends api.NoteContextAwareWidget {
super(...args);
this.markerCounter = 0;
this.balloonEditorCreate = null;
this.inComposition = false;
}

get position() {
Expand Down Expand Up @@ -184,7 +185,8 @@ class HighlightCodeBlockWidget extends api.NoteContextAwareWidget {
log("removing codeBlock at path " + JSON.stringify(change.position.toJSON()));

} else if (((change.type == "remove") || (change.type == "insert")) &&
change.position.parent.is('element', 'codeBlock')) {
change.position.parent.is('element', 'codeBlock') &&
!widget.inComposition) {
// Text was added or removed from the codeblock, force a
// highlight
const codeBlock = change.position.parent;
Expand All @@ -200,6 +202,18 @@ class HighlightCodeBlockWidget extends api.NoteContextAwareWidget {
return false;
});

// Ignore events fired between 'compositionstart' and 'compositionend' since
// it will trigger expected highlight to temporary input
// See: https://github.com/facebook/react/issues/3926
textEditor.editing.view.document.on('compositionstart', () => {
dbg("compositionstart");
widget.inComposition = true;
});
textEditor.editing.view.document.on('compositionend', () => {
dbg("compositionend");
widget.inComposition = false;
});

// This assumes the document is empty and a explicit call to highlight
// is not necessary here. Empty documents have a single children of type
// paragraph with no text
Expand Down