From f3e601e3403698b81c26d9c048231e73240d53c2 Mon Sep 17 00:00:00 2001 From: Vladimir Kunin Date: Mon, 16 May 2022 21:06:30 +0300 Subject: [PATCH] =?UTF-8?q?:bug:=20N=C2=B04834=20-=20Fix=20mentions=20work?= =?UTF-8?q?ing=20only=20with=20latin=20alphabet=20(no=20dash,=20no=20cyril?= =?UTF-8?q?lic,=20no=20asian,=20...)=20(#274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :bug: Add the 'pattern' parameter with the unicode Cyrillic block regex to the CKEditor mentions config. * Revert ":bug: Add the 'pattern' parameter with the unicode Cyrillic block regex to the CKEditor mentions config." This reverts commit 1f5ac000b677a44bdd4ee1160b2f972446516484. * :bug: Rewrite the CKEditor Mentions plugin regexp to make it suitable for all Unicode alphabets. --- js/ckeditor.on-init.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/ckeditor.on-init.js b/js/ckeditor.on-init.js index d485099938..25131cdcd3 100644 --- a/js/ckeditor.on-init.js +++ b/js/ckeditor.on-init.js @@ -21,3 +21,24 @@ if ((CKEDITOR !== undefined) && (CKEDITOR.plugins.registered['disabler'] === und }); } + +// Rewrite the CKEditor Mentions plugin regexp to make it suitable for all Unicode alphabets. +if (CKEDITOR !== undefined && CKEDITOR.plugins.registered['mentions']) { + // from https://github.com/ckeditor/ckeditor4/blob/a3786007fb979d7d7bff3d10c34a2d422935baed/plugins/mentions/plugin.js#L147 + function createPattern(marker, minChars) { + let pattern = marker + '[\\p{L}\\p{N}_-]'; + if ( minChars ) { + pattern += '{' + minChars + ',}'; + } else { + pattern += '*'; + } + pattern += '$'; + return new RegExp(pattern, 'u'); + } + + CKEDITOR.on('instanceLoaded', event => { + event.editor.config.mentions.forEach(config => { + config.pattern = createPattern(config.marker, config.minChars); + }); + }); +}