From 4a95e512b8a9359651a571edc417fec8f482691a Mon Sep 17 00:00:00 2001 From: Barry Hess Date: Fri, 22 Nov 2024 14:50:05 -0600 Subject: [PATCH 1/4] Focus the editor when link dialog is closed. This is especially useful when the ESC key is hit. Without this, the link dialog disappears, you expect to be able to continue editing, but the editor does not have focus. Now it does! --- src/exports/elements/tip-tap-editor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/exports/elements/tip-tap-editor.ts b/src/exports/elements/tip-tap-editor.ts index 5adfd576..7692fb65 100644 --- a/src/exports/elements/tip-tap-editor.ts +++ b/src/exports/elements/tip-tap-editor.ts @@ -303,6 +303,7 @@ export class TipTapEditor extends TipTapEditorBase { closeLinkDialog(): void { this.linkDialogExpanded = false; + this.editor.commands.focus(); } showLinkDialog(): void { From fc4e98986063bd17f549c7b255e591ea6dca6110 Mon Sep 17 00:00:00 2001 From: Barry Hess Date: Fri, 22 Nov 2024 15:07:42 -0600 Subject: [PATCH 2/4] Update addLink behavior to handle editing link without a full selection. When your cursor is within a node of linked text and the link dialog is opened, the intention is almost always to edit the link for the full node rather than insert a new link in place of the text for which the cursor is sitting. Here's how this interaction worked before: https://share.cleanshot.com/1NYHrBxP With this change, editing a link when the cursor is within a linked node will edit the link for the entire linked text rather than replacing or inserting the new link in place of or in the midst of the linked node text. Here is the change in action: https://share.cleanshot.com/gLjDmjwN --- src/exports/elements/tip-tap-editor.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/exports/elements/tip-tap-editor.ts b/src/exports/elements/tip-tap-editor.ts index 7692fb65..3caffa3a 100644 --- a/src/exports/elements/tip-tap-editor.ts +++ b/src/exports/elements/tip-tap-editor.ts @@ -357,18 +357,19 @@ export class TipTapEditor extends TipTapEditorBase { if (href) { this.closeLinkDialog(); inputElement.value = ""; - const chain = this.editor - ?.chain() - .extendMarkRange("link") - .setLink({ href }); - if (chain && this.editor?.state.selection.empty) { - chain.insertContent(href); + if (this.editor.state.selection.empty && !this.editor.getAttributes('link').href) { + const from = this.editor.state.selection.anchor; + this.editor.commands.insertContent(href); + const to = this.editor.state.selection.anchor; + this.editor.commands.setTextSelection({from, to}); } - if (chain) { - chain.run(); - } + const chain = this.editor + ?.chain() + .extendMarkRange("link") + .setLink({ href }) + .run(); } } From f7ad92bdf14f8c89900c7544545f8139c5b93f70 Mon Sep 17 00:00:00 2001 From: Barry Hess Date: Fri, 22 Nov 2024 15:12:28 -0600 Subject: [PATCH 3/4] Show invalid URL message when link validity is broken. Prior to this the text field would turn red, but the "Not a valid URL" message did not appear to the user. --- src/exports/elements/tip-tap-editor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/exports/elements/tip-tap-editor.ts b/src/exports/elements/tip-tap-editor.ts index 3caffa3a..6028ea62 100644 --- a/src/exports/elements/tip-tap-editor.ts +++ b/src/exports/elements/tip-tap-editor.ts @@ -351,6 +351,7 @@ export class TipTapEditor extends TipTapEditorBase { } catch (error) { inputElement.setCustomValidity("Not a valid URL"); this.__invalidLink__ = true; + inputElement.reportValidity(); return; } From de3fec30241a49921094bc7342772534d10db586 Mon Sep 17 00:00:00 2001 From: Konnor Rogers Date: Fri, 22 Nov 2024 16:48:21 -0500 Subject: [PATCH 4/4] Create violet-queens-perform.md --- .changeset/violet-queens-perform.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/violet-queens-perform.md diff --git a/.changeset/violet-queens-perform.md b/.changeset/violet-queens-perform.md new file mode 100644 index 00000000..cf32fb0e --- /dev/null +++ b/.changeset/violet-queens-perform.md @@ -0,0 +1,5 @@ +--- +"rhino-editor": patch +--- + +Fix the UX of link insertions