Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link handling tweaks #230

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-queens-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rhino-editor": patch
---

Fix the UX of link insertions
21 changes: 12 additions & 9 deletions src/exports/elements/tip-tap-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export class TipTapEditor extends TipTapEditorBase {

closeLinkDialog(): void {
this.linkDialogExpanded = false;
this.editor.commands.focus();
}

showLinkDialog(): void {
Expand Down Expand Up @@ -350,24 +351,26 @@ export class TipTapEditor extends TipTapEditorBase {
} catch (error) {
inputElement.setCustomValidity("Not a valid URL");
this.__invalidLink__ = true;
inputElement.reportValidity();
return;
}

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

Expand Down
Loading