From 3114e37c738e39bd9de157332e2ebf35e3d9b5ea Mon Sep 17 00:00:00 2001 From: Hannes Hertach Date: Wed, 17 Dec 2025 17:11:09 +0100 Subject: [PATCH 1/6] improve link pasting --- blocks/edit/prose/plugins/linkConverter.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/blocks/edit/prose/plugins/linkConverter.js b/blocks/edit/prose/plugins/linkConverter.js index e977c8ce..6f2a0680 100644 --- a/blocks/edit/prose/plugins/linkConverter.js +++ b/blocks/edit/prose/plugins/linkConverter.js @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-unresolved -import { Plugin } from 'da-y-wrapper'; +import { Plugin, TextSelection } from 'da-y-wrapper'; function isURL(text) { try { @@ -25,11 +25,22 @@ export default function linkConverter(schema) { const linkMark = schema.marks.link.create( { href: slice.content.content[0].content.content[0].text }, ); - const { from } = view.state.selection; + const { from, to } = view.state.selection; const { size } = slice.content.content[0].content; + const selectedSlice = view.state.doc.slice(from, to); + + // if we have some text selected, add the link to the selected text + if (selectedSlice.size > 0 + && selectedSlice.content.content.length === 1 + && selectedSlice.content.content[0].type.name === 'text') { + const addLinkMark = view.state.tr.addMark(from, to, linkMark); + view.dispatch(addLinkMark); + return true; + } + const addLinkMark = view.state.tr - .insert(from, slice.content.content[0].content) + .replaceWith(from, to, slice.content.content[0].content) .addMark(from, from + size, linkMark); view.dispatch(addLinkMark); From 082851eb6e6c7c72268af4d153473a29d2f79f65 Mon Sep 17 00:00:00 2001 From: Hannes Hertach Date: Wed, 17 Dec 2025 17:14:47 +0100 Subject: [PATCH 2/6] fix lint --- blocks/edit/prose/plugins/linkConverter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blocks/edit/prose/plugins/linkConverter.js b/blocks/edit/prose/plugins/linkConverter.js index 6f2a0680..4d105cb7 100644 --- a/blocks/edit/prose/plugins/linkConverter.js +++ b/blocks/edit/prose/plugins/linkConverter.js @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-unresolved -import { Plugin, TextSelection } from 'da-y-wrapper'; +import { Plugin } from 'da-y-wrapper'; function isURL(text) { try { @@ -31,8 +31,8 @@ export default function linkConverter(schema) { const selectedSlice = view.state.doc.slice(from, to); // if we have some text selected, add the link to the selected text - if (selectedSlice.size > 0 - && selectedSlice.content.content.length === 1 + if (selectedSlice.size > 0 + && selectedSlice.content.content.length === 1 && selectedSlice.content.content[0].type.name === 'text') { const addLinkMark = view.state.tr.addMark(from, to, linkMark); view.dispatch(addLinkMark); From 48c06fae25263ad23dc4dfcc55bae97664ab3dfc Mon Sep 17 00:00:00 2001 From: Hannes Hertach Date: Wed, 17 Dec 2025 17:19:02 +0100 Subject: [PATCH 3/6] fix test --- .../edit/prose/plugins/linkConverter.test.js | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/test/unit/blocks/edit/prose/plugins/linkConverter.test.js b/test/unit/blocks/edit/prose/plugins/linkConverter.test.js index 67f47c2c..2949d213 100644 --- a/test/unit/blocks/edit/prose/plugins/linkConverter.test.js +++ b/test/unit/blocks/edit/prose/plugins/linkConverter.test.js @@ -60,13 +60,24 @@ describe('Link converter plugin', () => { addedMark = mark; return this; }, + replaceWith: function replaceWith() { + return this; + }, + }; + + const mockDoc = { + slice: () => ({ + size: 0, + content: { content: [] }, + }), }; const mockView = { state: { - selection: { from: 10 }, + selection: { from: 10, to: 10 }, schema: baseSchema, tr, + doc: mockDoc, }, dispatch: () => {}, }; @@ -191,13 +202,24 @@ describe('Link converter plugin', () => { addedMark = mark; return this; }, + replaceWith: function replaceWith() { + return this; + }, + }; + + const mockDoc = { + slice: () => ({ + size: 0, + content: { content: [] }, + }), }; const mockView = { state: { - selection: { from: 10 }, + selection: { from: 10, to: 10 }, schema: baseSchema, tr, + doc: mockDoc, }, dispatch: () => {}, }; @@ -230,13 +252,24 @@ describe('Link converter plugin', () => { addedMark = mark; return this; }, + replaceWith: function replaceWith() { + return this; + }, + }; + + const mockDoc = { + slice: () => ({ + size: 0, + content: { content: [] }, + }), }; const mockView = { state: { - selection: { from: 10 }, + selection: { from: 10, to: 10 }, schema: baseSchema, tr, + doc: mockDoc, }, dispatch: () => {}, }; From 72b0932effed9420b0a87b0144884bc17964c5d1 Mon Sep 17 00:00:00 2001 From: Hannes Hertach Date: Thu, 18 Dec 2025 17:15:32 +0100 Subject: [PATCH 4/6] dont save links on cancel --- blocks/edit/prose/plugins/menu/linkItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/edit/prose/plugins/menu/linkItem.js b/blocks/edit/prose/plugins/menu/linkItem.js index c5d7978b..eaa678ba 100644 --- a/blocks/edit/prose/plugins/menu/linkItem.js +++ b/blocks/edit/prose/plugins/menu/linkItem.js @@ -247,7 +247,7 @@ export function linkItem(linkMarkType) { title: label, fields: promptFieldsConfiguration, callback, - saveOnClose: true, + saveOnClose: false, useLabelsAbove: true, }; linkPromptState.lastPrompt = openPrompt(promptOptions); From 7de06d6dbb0f1fa43676ada8391ee2fe62f68852 Mon Sep 17 00:00:00 2001 From: Hannes Hertach Date: Thu, 18 Dec 2025 17:26:36 +0100 Subject: [PATCH 5/6] remove highlight mark on close --- blocks/edit/prose/plugins/menu/linkItem.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blocks/edit/prose/plugins/menu/linkItem.js b/blocks/edit/prose/plugins/menu/linkItem.js index eaa678ba..53fd8775 100644 --- a/blocks/edit/prose/plugins/menu/linkItem.js +++ b/blocks/edit/prose/plugins/menu/linkItem.js @@ -251,6 +251,11 @@ export function linkItem(linkMarkType) { useLabelsAbove: true, }; linkPromptState.lastPrompt = openPrompt(promptOptions); + linkPromptState.lastPrompt.addEventListener('closed', () => { + const tr = view.state.tr; + tr.removeMark(currentRangeStart, currentRangeEnd, contextHighlightingMarkType); + dispatch(tr); + }) }, }); } From b6a062ad01d121787c40b410463e99ab1bbbf40a Mon Sep 17 00:00:00 2001 From: Hannes Hertach Date: Thu, 18 Dec 2025 17:28:29 +0100 Subject: [PATCH 6/6] fix lint --- blocks/edit/prose/plugins/menu/linkItem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/edit/prose/plugins/menu/linkItem.js b/blocks/edit/prose/plugins/menu/linkItem.js index 53fd8775..e5f8dd96 100644 --- a/blocks/edit/prose/plugins/menu/linkItem.js +++ b/blocks/edit/prose/plugins/menu/linkItem.js @@ -252,10 +252,10 @@ export function linkItem(linkMarkType) { }; linkPromptState.lastPrompt = openPrompt(promptOptions); linkPromptState.lastPrompt.addEventListener('closed', () => { - const tr = view.state.tr; + const { tr } = view.state; tr.removeMark(currentRangeStart, currentRangeEnd, contextHighlightingMarkType); dispatch(tr); - }) + }); }, }); }