quill
quill copied to clipboard
Calling `getFormat` when the editor doesn't have focus restore focus
Steps for Reproduction
I have an event handler on selection-change. If during the execution of the handler I call getFormat while the quill's editor doesn't have focus, then my editor gets the focus back.
Expected behavior:
getFormat should not change focus.
Actual behavior: My editor which doesn't have focus gets the focus.
Platforms: Windows with Electron 1.7.9
Version: 1.3.5
I assume you are calling with no parameters. In that case it focuses the editor to get the current selection.
That's correct. It seems that selection-change is called when getting out of focus and I'm mostly calling selection-change to get the format. I added a protection to make sure that the quill's editor has focus before asking for the format. However it would have been better to return a null/undefined format instead of having the side effects of focusing the editor.
@jhchen @manu-st any work around for this? I am running into the same issue. I need to call getFormat() and not set the selection.
@DarnellSh The one I made is to disable my handler for selection-change whenever I know for sure that the quills editor doesn't have focus.
Workaround I found is call quill.getSelection(false) first and then call getFormat with params like below:
const currentSelection = quill.getSelection(false);
const currentFormat = quill.getFormat(currentSelection.index, currentSelection.length);
Another workaround:
getFormat(): { [keys: string]: any } {
const hasFocus = this.quillEditor.hasFocus();
const format = this.quillEditor.getFormat();
if (hasFocus === false) {
this.quillEditor.blur();
}
return format;
}
Quill 2.0 has been released (announcement post) with many changes and fixes. If this is still an issue please create a new issue after reviewing our updated Contributing guide :pray: