mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
ve.ui.MWLinkAction: Use delayed sequence
The trailing space at the end of the regexp is no longer required to prevent matching (and executing) too soon. We also don't need to know about trailing punctuation. However, to prevent the match from ending in the middle of typing, we have to allow for ' ' and '-' at the end of the match. Tweaked tests to better match the intent now that a trailing space is not included, but they pass without changes too, the command is quite permissive. Bug: T117165 Depends-On: Ie36046fa43ce49f8a25c99f2de577eb296d68a51 Depends-On: I2af0a738afa43295bf6d7d612cac4349bc6cd20d Change-Id: I7c28d5c93b1a441387ad05a75846af83d2b21b6a
This commit is contained in:
parent
13eb3d9027
commit
5afd15b2cc
|
@ -29,10 +29,10 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
|||
{
|
||||
msg: 'Autolink valid RFC',
|
||||
html: '<p><b>RFC 1234 xyz</b></p>',
|
||||
rangeOrSelection: new ve.Range( 1, 10 ),
|
||||
rangeOrSelection: new ve.Range( 1, 9 ),
|
||||
method: 'autolinkMagicLink',
|
||||
expectedRangeOrSelection: new ve.Range( 4 ),
|
||||
expectedOriginalRangeOrSelection: new ve.Range( 10 ),
|
||||
expectedRangeOrSelection: new ve.Range( 3 ),
|
||||
expectedOriginalRangeOrSelection: new ve.Range( 9 ),
|
||||
expectedData: function ( data ) {
|
||||
data.splice( 1, 8, {
|
||||
type: 'link/mwMagic',
|
||||
|
@ -50,9 +50,9 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
|||
{
|
||||
msg: 'Don\'t autolink invalid RFC',
|
||||
html: '<p><b>RFC 123x xyz</b></p>',
|
||||
rangeOrSelection: new ve.Range( 1, 10 ),
|
||||
rangeOrSelection: new ve.Range( 1, 9 ),
|
||||
method: 'autolinkMagicLink',
|
||||
expectedRangeOrSelection: new ve.Range( 1, 10 ),
|
||||
expectedRangeOrSelection: new ve.Range( 1, 9 ),
|
||||
expectedData: function () {
|
||||
/* no change, no link */
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
|||
{
|
||||
msg: 'Autolink valid PMID',
|
||||
html: '<p><b>PMID 1234 xyz</b></p>',
|
||||
rangeOrSelection: new ve.Range( 1, 11 ),
|
||||
rangeOrSelection: new ve.Range( 1, 10 ),
|
||||
method: 'autolinkMagicLink',
|
||||
expectedRangeOrSelection: new ve.Range( 4 ),
|
||||
expectedOriginalRangeOrSelection: new ve.Range( 11 ),
|
||||
expectedRangeOrSelection: new ve.Range( 3 ),
|
||||
expectedOriginalRangeOrSelection: new ve.Range( 10 ),
|
||||
expectedData: function ( data ) {
|
||||
data.splice( 1, 9, {
|
||||
type: 'link/mwMagic',
|
||||
|
@ -81,9 +81,9 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
|||
{
|
||||
msg: 'Don\'t autolink invalid PMID',
|
||||
html: '<p><b>PMID 123x xyz</b></p>',
|
||||
rangeOrSelection: new ve.Range( 1, 11 ),
|
||||
rangeOrSelection: new ve.Range( 1, 10 ),
|
||||
method: 'autolinkMagicLink',
|
||||
expectedRangeOrSelection: new ve.Range( 1, 11 ),
|
||||
expectedRangeOrSelection: new ve.Range( 1, 10 ),
|
||||
expectedData: function () {
|
||||
/* no change, no link */
|
||||
}
|
||||
|
@ -91,10 +91,10 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
|||
{
|
||||
msg: 'Autolink valid ISBN',
|
||||
html: '<p><b>ISBN 978-0596517748 xyz</b></p>',
|
||||
rangeOrSelection: new ve.Range( 1, 21 ),
|
||||
rangeOrSelection: new ve.Range( 1, 20 ),
|
||||
method: 'autolinkMagicLink',
|
||||
expectedRangeOrSelection: new ve.Range( 4 ),
|
||||
expectedOriginalRangeOrSelection: new ve.Range( 21 ),
|
||||
expectedRangeOrSelection: new ve.Range( 3 ),
|
||||
expectedOriginalRangeOrSelection: new ve.Range( 20 ),
|
||||
expectedData: function ( data ) {
|
||||
data.splice( 1, 19, {
|
||||
type: 'link/mwMagic',
|
||||
|
@ -112,9 +112,9 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
|||
{
|
||||
msg: 'Don\'t autolink invalid ISBN',
|
||||
html: '<p><b>ISBN 978-059651774 xyz</b></p>',
|
||||
rangeOrSelection: new ve.Range( 1, 20 ),
|
||||
rangeOrSelection: new ve.Range( 1, 19 ),
|
||||
method: 'autolinkMagicLink',
|
||||
expectedRangeOrSelection: new ve.Range( 1, 20 ),
|
||||
expectedRangeOrSelection: new ve.Range( 1, 19 ),
|
||||
expectedData: function () {
|
||||
/* no change, no link */
|
||||
}
|
||||
|
|
|
@ -169,7 +169,5 @@ ve.ui.commandRegistry.register(
|
|||
ve.ui.sequenceRegistry.register(
|
||||
// This regexp doesn't have to be precise; we'll validate the magic
|
||||
// link in #autolinkMagicLink above.
|
||||
// The trailing \S* covers any trailing punctuation, which will be
|
||||
// stripped before validating the link.
|
||||
new ve.ui.Sequence( 'autolinkMagicLink', 'autolinkMagicLink', /\b(RFC|PMID|ISBN)\s+[0-9]([- 0-9]*[0-9Xx])?\S*(\s|\n+)$/, 0, true )
|
||||
new ve.ui.Sequence( 'autolinkMagicLink', 'autolinkMagicLink', /\b(RFC|PMID|ISBN)\s+[0-9]([- 0-9]*)[0-9Xx][- ]?$/, 0, true, true )
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue