Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: dont overwrite other link commands
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Mar 19, 2025
commit 0c3bcadb09245e387b9ecf33d8d4169672495ec6
2 changes: 1 addition & 1 deletion cypress/e2e/marks/Link.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Link marks', { retries: 0 }, () => {

it('can run on normal paragraph', () => {
prepareEditor('hello\n', 3)
expect(editor.can().insertOrSetLink()).toBe(true)
expect(editor.can().insertOrSetLink().run()).to.equal(true)
})

it('will insert a link in a normal paragraph', () => {
Expand Down
22 changes: 17 additions & 5 deletions src/marks/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const Link = TipTapLink.extend({
},
addCommands() {
return {
...this.parent?.(),
insertOrSetLink: (text, attrs) => ({ state, chain, commands }) => {
// Check if any text is selected,
// if not insert the link using the given text property
Expand All @@ -103,14 +104,25 @@ const Link = TipTapLink.extend({
}
})
commands.deleteRange(getMarkRange(state.selection.$anchor, state.schema.marks.link, { href }))
return chain().insertContent({
type: 'text',
marks: [{
type: 'link',
attrs,
}],
text,
})
}
return chain().insertContent({
type: 'text',
marks: [{
type: 'link',
attrs,
type: 'paragraph',
content: [{
type: 'text',
marks: [{
type: 'link',
attrs,
}],
text,
}],
text,
})
} else {
return commands.setLink(attrs)
Expand Down