Skip to content

Commit 588abba

Browse files
bjhessKonnorRogers
andauthored
Link handling tweaks (#230)
* 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! * 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 * 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. * Create violet-queens-perform.md --------- Co-authored-by: Konnor Rogers <konnor5456@gmail.com>
1 parent 01dbfbf commit 588abba

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

.changeset/violet-queens-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rhino-editor": patch
3+
---
4+
5+
Fix the UX of link insertions

src/exports/elements/tip-tap-editor.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export class TipTapEditor extends TipTapEditorBase {
303303

304304
closeLinkDialog(): void {
305305
this.linkDialogExpanded = false;
306+
this.editor.commands.focus();
306307
}
307308

308309
showLinkDialog(): void {
@@ -350,24 +351,26 @@ export class TipTapEditor extends TipTapEditorBase {
350351
} catch (error) {
351352
inputElement.setCustomValidity("Not a valid URL");
352353
this.__invalidLink__ = true;
354+
inputElement.reportValidity();
353355
return;
354356
}
355357

356358
if (href) {
357359
this.closeLinkDialog();
358360
inputElement.value = "";
359-
const chain = this.editor
360-
?.chain()
361-
.extendMarkRange("link")
362-
.setLink({ href });
363361

364-
if (chain && this.editor?.state.selection.empty) {
365-
chain.insertContent(href);
362+
if (this.editor.state.selection.empty && !this.editor.getAttributes('link').href) {
363+
const from = this.editor.state.selection.anchor;
364+
this.editor.commands.insertContent(href);
365+
const to = this.editor.state.selection.anchor;
366+
this.editor.commands.setTextSelection({from, to});
366367
}
367368

368-
if (chain) {
369-
chain.run();
370-
}
369+
const chain = this.editor
370+
?.chain()
371+
.extendMarkRange("link")
372+
.setLink({ href })
373+
.run();
371374
}
372375
}
373376

0 commit comments

Comments
 (0)