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

Commit

Permalink
Merge pull request #83 from ckeditor/t/ckeditor5-word-count/5
Browse files Browse the repository at this point in the history
Other: Use RegExp Unicode support feature detection form ckeditor5-utils.

BREAKING CHANGE: The `mention/featuredetection` namespace is removed. Please use `env.features` from ckeditor5-utils instead.
  • Loading branch information
jodator authored Jul 23, 2019
2 parents 34f9bc8 + d7e490c commit d47923e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 47 deletions.
36 changes: 0 additions & 36 deletions src/featuredetection.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
import featureDetection from './featuredetection';
import env from '@ckeditor/ckeditor5-utils/src/env';
import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
Expand Down Expand Up @@ -536,8 +536,8 @@ function getBalloonPanelPositions( preferredPosition ) {
export function createRegExp( marker, minimumCharacters ) {
const numberOfCharacters = minimumCharacters == 0 ? '*' : `{${ minimumCharacters },}`;

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

// The pattern consists of 3 groups:
// - 0 (non-capturing): Opening sequence - start of the line, space or an opening punctuation character like "(" or "\"",
Expand Down
15 changes: 7 additions & 8 deletions tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextu
import env from '@ckeditor/ckeditor5-utils/src/env';

import MentionUI, { createRegExp } from '../src/mentionui';
import featureDetection from '../src/featuredetection';
import MentionEditing from '../src/mentionediting';
import MentionsView from '../src/ui/mentionsview';
import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
Expand Down Expand Up @@ -449,10 +448,10 @@ describe( 'MentionUI', () => {
let regExpStub;

// Cache the original value to restore it after the tests.
const originalGroupSupport = featureDetection.isUnicodeGroupSupported;
const originalGroupSupport = env.features.isRegExpUnicodePropertySupported;

before( () => {
featureDetection.isUnicodeGroupSupported = false;
env.features.isRegExpUnicodePropertySupported = false;
} );

beforeEach( () => {
Expand All @@ -465,18 +464,18 @@ describe( 'MentionUI', () => {
} );

after( () => {
featureDetection.isUnicodeGroupSupported = originalGroupSupport;
env.features.isRegExpUnicodePropertySupported = originalGroupSupport;
} );

it( 'returns a simplified RegExp for browsers not supporting Unicode punctuation groups', () => {
featureDetection.isUnicodeGroupSupported = false;
env.features.isRegExpUnicodePropertySupported = false;
createRegExp( '@', 2 );
sinon.assert.calledOnce( regExpStub );
sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\(\\[{"\'])([@])([_a-zA-ZÀ-ž0-9]{2,})$', 'u' );
} );

it( 'returns a ES2018 RegExp for browsers supporting Unicode punctuation groups', () => {
featureDetection.isUnicodeGroupSupported = true;
env.features.isRegExpUnicodePropertySupported = true;
createRegExp( '@', 2 );
sinon.assert.calledOnce( regExpStub );
sinon.assert.calledWithExactly( regExpStub, '(?:^|[ \\p{Ps}\\p{Pi}"\'])([@])([_\\p{L}\\p{N}]{2,})$', 'u' );
Expand Down Expand Up @@ -564,7 +563,7 @@ describe( 'MentionUI', () => {
// Belongs to Pi (Punctuation, Initial quote) group:
'«', '‹', '⸌', ' ⸂', '⸠'
] ) {
testOpeningPunctuationCharacter( character, !featureDetection.isUnicodeGroupSupported );
testOpeningPunctuationCharacter( character, !env.features.isRegExpUnicodePropertySupported );
}

it( 'should not show panel for marker in the middle of other word', () => {
Expand Down Expand Up @@ -834,7 +833,7 @@ describe( 'MentionUI', () => {
} );

it( 'should open panel for unicode character ב', function() {
if ( !featureDetection.isUnicodeGroupSupported ) {
if ( !env.features.isRegExpUnicodePropertySupported ) {
this.skip();
}

Expand Down

0 comments on commit d47923e

Please sign in to comment.