Skip to content

Commit

Permalink
Allow invalid bare www URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisSpomer committed Jan 15, 2025
1 parent a2023ed commit 7920016
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import TableRow from "@tiptap/extension-table-row"
import Typography from "@tiptap/extension-typography"
import { navigating } from "$app/stores"
import { Bold, Italic, ClearFormat, Link, UploadImage, X } from "$lib/icons"
import { Bold, Italic, ClearFormat, Link, UploadImage } from "$lib/icons"
import { uploadImage } from "$lib/sdk"
import { expandUserUrl } from "$lib/utils/url"
import Button from "./Button.svelte"
import FocusWithin from "./FocusWithin.svelte"
import PopupFrame from "./PopupFrame.svelte"
Expand Down Expand Up @@ -352,9 +353,11 @@
}
else
{
editor.chain().focus().insertContent("Link").run()
const DefaultLinkText = "Link"
editor.chain().focus().insertContent(DefaultLinkText).run()
const newPos = editor.state.selection
editor.chain().setTextSelection({ from: newPos.to - 4, to: newPos.to }).setLink({ href:"https://" }).setTextSelection(newPos.to).run()
editor.chain().setTextSelection({ from: newPos.to - DefaultLinkText.length, to: newPos.to }).setLink({ href:"https://" }).run()
}
// TODO: if (linkEditor) linkEditor.focus()
return true // to indicate that the keyboard shortcut was handled
Expand All @@ -367,7 +370,7 @@
if (linkRange)
{
if (!isEmptyLink)
editor.chain().setTextSelection(linkRange).unsetLink().setLink({ href: linkEditorHref }).run()
editor.chain().setTextSelection(linkRange).unsetLink().setLink({ href: expandUserUrl(linkEditorHref) }).run()
else
editor.chain().setTextSelection(linkRange).unsetLink().run()
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function expandUserUrl(input: string): string
{
if (input.indexOf("/") >= 0) return input
return `https://${input}`
}

0 comments on commit 7920016

Please sign in to comment.