Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit aa7d04d

Browse files
authored
Merge pull request #93 from ckeditor/t/ckeditor5/6398
Other: Mentions can now be matched by any character typed. Closes ckeditor/ckeditor5#6398.
2 parents 4d678d3 + c7e128d commit aa7d04d

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

src/mentionui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ export function createRegExp( marker, minimumCharacters ) {
640640
const numberOfCharacters = minimumCharacters == 0 ? '*' : `{${ minimumCharacters },}`;
641641

642642
const openAfterCharacters = env.features.isRegExpUnicodePropertySupported ? '\\p{Ps}\\p{Pi}"\'' : '\\(\\[{"\'';
643-
const mentionCharacters = env.features.isRegExpUnicodePropertySupported ? '\\p{L}\\p{N}' : 'a-zA-ZÀ-ž0-9';
643+
const mentionCharacters = '\\S';
644644

645645
// The pattern consists of 3 groups:
646646
// - 0 (non-capturing): Opening sequence - start of the line, space or an opening punctuation character like "(" or "\"",
@@ -649,7 +649,7 @@ export function createRegExp( marker, minimumCharacters ) {
649649
//
650650
// The pattern matches up to the caret (end of string switch - $).
651651
// (0: opening sequence )(1: marker )(2: typed mention )$
652-
const pattern = `(?:^|[ ${ openAfterCharacters }])([${ marker }])([_${ mentionCharacters }]${ numberOfCharacters })$`;
652+
const pattern = `(?:^|[ ${ openAfterCharacters }])([${ marker }])([${ mentionCharacters }]${ numberOfCharacters })$`;
653653

654654
return new RegExp( pattern, 'u' );
655655
}

tests/manual/mention.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ ClassicEditor
165165
'#a01', '#a02', '#a03', '#a04', '#a05', '#a06', '#a07', '#a08', '#a09', '#a10',
166166
'#a11', '#a12', '#a13', '#a14', '#a15', '#a16', '#a17', '#a18', '#a19', '#a20'
167167
]
168+
},
169+
{
170+
marker: ':',
171+
feed: [
172+
':+1:', ':-1:', ':@(at-sign):', ':$(dollar-sign):', ':#(hash-sign):'
173+
]
168174
}
169175
]
170176
}

tests/manual/mention.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ The feeds:
2121
- ...
2222
- a20
2323

24+
3. Static list of "special characters" items (`:` marker)
25+
26+
- :+1:
27+
- :-1:
28+
- :@(at-sign):
29+
- :$(dollar-sign):
30+
- :#(hash-sign):
31+
2432
### Interaction
2533

2634
You can interact with mention panel with keyboard:

tests/mentionui.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,14 @@ describe( 'MentionUI', () => {
518518
env.features.isRegExpUnicodePropertySupported = false;
519519
createRegExp( '@', 2 );
520520
sinon.assert.calledOnce( regExpStub );
521-
sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\(\\[{"\'])([@])([_a-zA-ZÀ-ž0-9]{2,})$', 'u' );
521+
sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\(\\[{"\'])([@])([\\S]{2,})$', 'u' );
522522
} );
523523

524524
it( 'returns a ES2018 RegExp for browsers supporting Unicode punctuation groups', () => {
525525
env.features.isRegExpUnicodePropertySupported = true;
526526
createRegExp( '@', 2 );
527527
sinon.assert.calledOnce( regExpStub );
528-
sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\p{Ps}\\p{Pi}"\'])([@])([_\\p{L}\\p{N}]{2,})$', 'u' );
528+
sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\p{Ps}\\p{Pi}"\'])([@])([\\S]{2,})$', 'u' );
529529
} );
530530
} );
531531

@@ -1916,7 +1916,11 @@ describe( 'MentionUI', () => {
19161916
},
19171917
{
19181918
marker: '$',
1919-
feed: [ '$a1', '$a2', '$a3', '$a4', '$a5' ]
1919+
feed: [
1920+
'$a1', '$a2', '$a3', '$a4',
1921+
// A case of mention with a marker character from other feed. See #6398.
1922+
'$a@'
1923+
]
19201924
}
19211925
]
19221926
} );
@@ -1971,6 +1975,43 @@ describe( 'MentionUI', () => {
19711975
expect( mentionsView.items ).to.have.length( 3 );
19721976
} );
19731977
} );
1978+
1979+
it( 'should show panel for matched marker if it contains the other configured marker', () => {
1980+
setData( model, '<paragraph>foo []</paragraph>' );
1981+
1982+
model.change( writer => {
1983+
writer.insertText( '@', doc.selection.getFirstPosition() );
1984+
} );
1985+
1986+
return waitForDebounce()
1987+
.then( () => {
1988+
expect( panelView.isVisible ).to.be.true;
1989+
expect( editor.model.markers.has( 'mention' ) ).to.be.true;
1990+
expect( mentionsView.items ).to.have.length( 3 );
1991+
1992+
mentionsView.items.get( 0 ).children.get( 0 ).fire( 'execute' );
1993+
} )
1994+
.then( waitForDebounce )
1995+
.then( () => {
1996+
expect( panelView.isVisible ).to.be.false;
1997+
expect( editor.model.markers.has( 'mention' ) ).to.be.false;
1998+
1999+
model.change( writer => {
2000+
writer.insertText( '$a', doc.selection.getFirstPosition() );
2001+
} );
2002+
} )
2003+
.then( waitForDebounce )
2004+
.then( () => {
2005+
model.change( writer => {
2006+
writer.insertText( '@', doc.selection.getFirstPosition() );
2007+
} );
2008+
} )
2009+
.then( waitForDebounce )
2010+
.then( () => {
2011+
expect( panelView.isVisible ).to.be.true;
2012+
expect( editor.model.markers.has( 'mention' ) ).to.be.true;
2013+
} );
2014+
} );
19742015
} );
19752016

19762017
function testExecuteKey( name, keyCode, feedItems ) {

0 commit comments

Comments
 (0)