Cscott has uploaded a new change for review. https://gerrit.wikimedia.org/r/240910
Change subject: Allow autolinking inside list items ...................................................................... Allow autolinking inside list items Bug: T113535 Change-Id: I18b73514e5a3d967cce02d9706a11e30ede71d9a --- M src/ui/actions/ve.ui.LinkAction.js M src/ui/ve.ui.SequenceRegistry.js 2 files changed, 16 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/10/240910/1 diff --git a/src/ui/actions/ve.ui.LinkAction.js b/src/ui/actions/ve.ui.LinkAction.js index 13a8c92..e10bcd0 100644 --- a/src/ui/actions/ve.ui.LinkAction.js +++ b/src/ui/actions/ve.ui.LinkAction.js @@ -187,7 +187,7 @@ ve.ui.LinkAction.static.autolinkRegExp = new RegExp( - '\\b' + ve.init.platform.getUnanchoredExternalLinkUrlProtocolsRegExp().source + '\\S+(\\s|\\n\\n)$', + '\\b' + ve.init.platform.getUnanchoredExternalLinkUrlProtocolsRegExp().source + '\\S+(\\s|\\n+)$', 'i' ); diff --git a/src/ui/ve.ui.SequenceRegistry.js b/src/ui/ve.ui.SequenceRegistry.js index edd7085..6493a0e 100644 --- a/src/ui/ve.ui.SequenceRegistry.js +++ b/src/ui/ve.ui.SequenceRegistry.js @@ -48,17 +48,27 @@ * for each. */ ve.ui.SequenceRegistry.prototype.findMatching = function ( data, offset ) { - var textStart, plaintext, name, range, sequences = []; + var textStart, plaintext, name, range, mode = 0, sequences = []; // To avoid blowup when matching RegExp sequences, we're going to grab // all the plaintext to the left (until the nearest node) *once* and pass // it to each sequence matcher. We're also going to hard-limit that // plaintext to 256 characters to ensure we don't run into O(N^2) // slowdown when inserting N characters of plain text. + + // First skip over open elements, then close elements, to ensure that + // pressing enter after a (possibly nested) list item or inside a + // paragraph works properly. Typing "foo\n" inside a paragraph creates + // "foo</p><p>" in the content model, and typing "foo\n" inside a list + // creates "foo</p></li><li><p>" -- we want to give the matcher a + // chance to match "foo\n+" in these cases. for ( textStart = offset - 1; textStart >= 0 && ( offset - textStart ) <= 256; textStart-- ) { - // Ignore an element if it occurs in the last two context characters. - // Typing "foo\n" creates "foo</p><p>" in the data model, and we want - // to give the matcher a chance against it. - if ( data.isElementData( textStart ) && ( offset - textStart ) > 2 ) { + if ( mode === 0 && !data.isOpenElementData( textStart ) ) { + mode++; + } + if ( mode === 1 && !data.isCloseElementData( textStart ) ) { + mode++; + } + if ( mode === 2 && data.isElementData( textStart ) ) { break; } } -- To view, visit https://gerrit.wikimedia.org/r/240910 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I18b73514e5a3d967cce02d9706a11e30ede71d9a Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Cscott <canan...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits