Skip to content

Commit

Permalink
Merge pull request #413 from tautastic/tautastic/issue412
Browse files Browse the repository at this point in the history
bug: Usage of `editor.chain().focus()` removes focus from tippy popover  Fixes #412
  • Loading branch information
andrewdoro authored Jul 15, 2024
2 parents fb42c23 + ad2e6f8 commit d0555b9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/web/components/tailwind/selectors/color-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const ColorSelector = ({ open, onOpenChange }: ColorSelectorProps) => {
.focus()
.setColor(color || "")
.run();
onOpenChange(false);
}}
className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-accent"
>
Expand All @@ -153,7 +154,8 @@ export const ColorSelector = ({ open, onOpenChange }: ColorSelectorProps) => {
key={name}
onSelect={() => {
editor.commands.unsetHighlight();
name !== "Default" && editor.commands.setHighlight({ color });
name !== "Default" && editor.chain().focus().setHighlight({ color }).run();
onOpenChange(false);
}}
className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-accent"
>
Expand Down
6 changes: 5 additions & 1 deletion apps/web/components/tailwind/selectors/link-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export const LinkSelector = ({ open, onOpenChange }: LinkSelectorProps) => {
e.preventDefault();
const input = target[0] as HTMLInputElement;
const url = getUrlFromString(input.value);
url && editor.chain().focus().setLink({ href: url }).run();
if (url) {
editor.chain().focus().setLink({ href: url }).run();
onOpenChange(false);
}
}}
className="flex p-1 "
>
Expand All @@ -80,6 +83,7 @@ export const LinkSelector = ({ open, onOpenChange }: LinkSelectorProps) => {
onClick={() => {
editor.chain().focus().unsetLink().run();
inputRef.current.value = "";
onOpenChange(false);
}}
>
<Trash className="h-4 w-4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const ColorSelector = ({ open, onOpenChange }: ColorSelectorProps) => {
.focus()
.setColor(color || "")
.run();
onOpenChange(false);
}}
className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-accent"
>
Expand All @@ -169,7 +170,8 @@ export const ColorSelector = ({ open, onOpenChange }: ColorSelectorProps) => {
key={index}
onSelect={() => {
editor.commands.unsetHighlight();
name !== "Default" && editor.commands.setHighlight({ color });
name !== "Default" && editor.chain().focus().setHighlight({ color }).run();
onOpenChange(false);
}}
className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-accent"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export const LinkSelector = ({ open, onOpenChange }: LinkSelectorProps) => {
e.preventDefault();
const input = target[0] as HTMLInputElement;
const url = getUrlFromString(input.value);
url && editor.chain().focus().setLink({ href: url }).run();
if (url) {
editor.chain().focus().setLink({ href: url }).run();
onOpenChange(false);
}
}}
className="flex p-1 "
>
Expand All @@ -92,6 +95,7 @@ export const LinkSelector = ({ open, onOpenChange }: LinkSelectorProps) => {
className="flex h-8 items-center rounded-sm p-1 text-red-600 transition-all hover:bg-red-100 dark:hover:bg-red-800"
onClick={() => {
editor.chain().focus().unsetLink().run();
onOpenChange(false);
}}
>
<Trash className="h-4 w-4" />
Expand Down

0 comments on commit d0555b9

Please sign in to comment.