quill icon indicating copy to clipboard operation
quill copied to clipboard

Calling `getFormat` when the editor doesn't have focus restore focus

Open manu-st opened this issue 7 years ago • 5 comments

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

manu-st avatar Feb 28 '18 07:02 manu-st

I assume you are calling with no parameters. In that case it focuses the editor to get the current selection.

jhchen avatar Mar 10 '18 02:03 jhchen

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.

manu-st avatar Mar 10 '18 05:03 manu-st

@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.

DJShump08 avatar Jul 31 '18 18:07 DJShump08

@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.

manu-st avatar Aug 01 '18 05:08 manu-st

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);

Hanho-Kim avatar Jun 29 '22 16:06 Hanho-Kim

Another workaround:

getFormat(): { [keys: string]: any } {
  const hasFocus = this.quillEditor.hasFocus();
  const format = this.quillEditor.getFormat();
  if (hasFocus === false) {
    this.quillEditor.blur();
  }
  return format;
}

zzjzz9266a avatar Mar 15 '23 11:03 zzjzz9266a

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:

quill-bot avatar Apr 17 '24 10:04 quill-bot