Skip to content

Commit

Permalink
Address PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AagashRaaj committed Aug 25, 2023
1 parent 710c577 commit c7d71c2
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/nimble-components/src/rich-text-editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class RichTextEditor extends FoundationElement {
*/
public boldButtonClick(): void {
this.tiptapEditor.chain().focus().toggleBold().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
}

/**
Expand All @@ -111,7 +111,7 @@ export class RichTextEditor extends FoundationElement {
public boldButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleBold().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
return false;
}
return true;
Expand All @@ -123,7 +123,7 @@ export class RichTextEditor extends FoundationElement {
*/
public italicsButtonClick(): void {
this.tiptapEditor.chain().focus().toggleItalic().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
}

/**
Expand All @@ -133,7 +133,7 @@ export class RichTextEditor extends FoundationElement {
public italicsButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleItalic().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
return false;
}
return true;
Expand All @@ -145,7 +145,7 @@ export class RichTextEditor extends FoundationElement {
*/
public bulletListButtonClick(): void {
this.tiptapEditor.chain().focus().toggleBulletList().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
}

/**
Expand All @@ -155,7 +155,7 @@ export class RichTextEditor extends FoundationElement {
public bulletListButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleBulletList().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
return false;
}
return true;
Expand All @@ -167,7 +167,7 @@ export class RichTextEditor extends FoundationElement {
*/
public numberedListButtonClick(): void {
this.tiptapEditor.chain().focus().toggleOrderedList().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
}

/**
Expand All @@ -177,7 +177,7 @@ export class RichTextEditor extends FoundationElement {
public numberedListButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleOrderedList().run();
this.focusEditorInFirefoxEnv();
this.focusEditorInFirefox();
return false;
}
return true;
Expand Down Expand Up @@ -357,10 +357,9 @@ export class RichTextEditor extends FoundationElement {
}

// In Firefox browser, Once the editor gets focused, the blinking caret will be visible until we click format buttons (Bold, Italic ...) in the Firefox browser (Changing focus).
// But once the any of the buttons clicked, the editor internally has its focus but the blinking caret disappears.
// As a workaround, manually triggering blur and setting focus on editor will hepls making the caret re-appears.
// It seems like this issue in not fixed in firefox browser yet, Created Issue https://github.com/ni/nimble/issues/1454 tracks removal of this workaround.
private focusEditorInFirefoxEnv(): void {
// But once any of the toolbar button is clicked, editor internally has its focus but the blinking caret disappears.
// As a workaround, manually triggering blur and setting focus on editor makes the blinking caret to re-appear.
private focusEditorInFirefox(): void {
const browserInfo = navigator.userAgent;
if (browserInfo.includes('Firefox')) {
this.tiptapEditor.commands.blur();
Expand Down

0 comments on commit c7d71c2

Please sign in to comment.