From 4e267e6032d213eb1fd0360ee4c5bd1d44b4ef85 Mon Sep 17 00:00:00 2001 From: Lucy Wang Date: Mon, 7 Jun 2021 12:54:02 +0800 Subject: [PATCH] should not auto link immediately after a link --- core/components/__tests__/link.test.js | 29 ++++++++++++++++++++++++++ core/components/link.js | 23 +++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/core/components/__tests__/link.test.js b/core/components/__tests__/link.test.js index 68724e9ea..551ada89b 100644 --- a/core/components/__tests__/link.test.js +++ b/core/components/__tests__/link.test.js @@ -684,6 +684,35 @@ describe('Input rule', () => { , ], + [ + + + 123.com + {' '}def.com[] + + , + + + 123.com + {' '}def.com{' '}[] + + , + ], + // No auto link when there is no space after the prev link + [ + + + 123.com + def.com[] + + , + + + 123.com + def.com [] + + , + ], ])('%# input rule', async (input, expected) => { const { editorView } = testEditor(input); diff --git a/core/components/link.js b/core/components/link.js index ec34331c7..8b6c5a86a 100644 --- a/core/components/link.js +++ b/core/components/link.js @@ -124,7 +124,28 @@ function autoLinkInputRule(type) { return null; } const [_, leadingSpace, text, scheme] = match; - // If no scheme, use default scheme http:// + if (!leadingSpace) { + // Do nothing there is already a link within [start, end] This is for + // cases like "abc.comdef.com[]". In such case typing a space + // after def.com should not auto link. + let ignore = false; + state.doc.nodesBetween(start, end, (node) => { + if (ignore) { + return false; + } + if (type.isInSet(node.marks)) { + ignore = true; + return false; + } + return true; + }); + + if (ignore) { + return null; + } + } + // If no scheme, use default scheme "http://". Most https sites would do a + // redirect for http request anyway. const href = scheme ? text : `http://${text}`; const tr = state.tr; tr.addMark(