@ckeditor/ckeditor5-mention 41.1.0 → 41.3.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/build/mention.js +1 -1
- package/dist/content-index.css +4 -0
- package/dist/editor-index.css +17 -0
- package/dist/index.css +34 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +1223 -0
- package/dist/index.js.map +1 -0
- package/dist/types/augmentation.d.ts +23 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/mention.d.ts +77 -0
- package/dist/types/mentioncommand.d.ts +77 -0
- package/dist/types/mentionconfig.d.ts +265 -0
- package/dist/types/mentionediting.d.ts +43 -0
- package/dist/types/mentionui.d.ts +102 -0
- package/dist/types/ui/domwrapperview.d.ts +41 -0
- package/dist/types/ui/mentionlistitemview.d.ts +15 -0
- package/dist/types/ui/mentionsview.d.ts +60 -0
- package/package.json +3 -2
- package/src/mentioncommand.js +23 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-mention",
|
3
|
-
"version": "41.
|
3
|
+
"version": "41.3.0-alpha.0",
|
4
4
|
"description": "Mention feature for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -13,7 +13,7 @@
|
|
13
13
|
"type": "module",
|
14
14
|
"main": "src/index.js",
|
15
15
|
"dependencies": {
|
16
|
-
"ckeditor5": "41.
|
16
|
+
"ckeditor5": "41.3.0-alpha.0",
|
17
17
|
"lodash-es": "4.17.21"
|
18
18
|
},
|
19
19
|
"author": "CKSource (http://cksource.com/)",
|
@@ -26,6 +26,7 @@
|
|
26
26
|
"directory": "packages/ckeditor5-mention"
|
27
27
|
},
|
28
28
|
"files": [
|
29
|
+
"dist",
|
29
30
|
"lang",
|
30
31
|
"src/**/*.js",
|
31
32
|
"src/**/*.d.ts",
|
package/src/mentioncommand.js
CHANGED
@@ -8,6 +8,11 @@
|
|
8
8
|
import { Command } from 'ckeditor5/src/core.js';
|
9
9
|
import { CKEditorError, toMap } from 'ckeditor5/src/utils.js';
|
10
10
|
import { _addMentionAttributes } from './mentionediting.js';
|
11
|
+
const BRACKET_PAIRS = {
|
12
|
+
'(': ')',
|
13
|
+
'[': ']',
|
14
|
+
'{': '}'
|
15
|
+
};
|
11
16
|
/**
|
12
17
|
* The mention command.
|
13
18
|
*
|
@@ -138,8 +143,24 @@ export default class MentionCommand extends Command {
|
|
138
143
|
const attributesWithMention = new Map(currentAttributes.entries());
|
139
144
|
attributesWithMention.set('mention', mention);
|
140
145
|
// Replace a range with the text with a mention.
|
141
|
-
model.insertContent(writer.createText(mentionText, attributesWithMention), range);
|
142
|
-
|
146
|
+
const insertionRange = model.insertContent(writer.createText(mentionText, attributesWithMention), range);
|
147
|
+
const nodeBefore = insertionRange.start.nodeBefore;
|
148
|
+
const nodeAfter = insertionRange.end.nodeAfter;
|
149
|
+
const isFollowedByWhiteSpace = nodeAfter && nodeAfter.is('$text') && nodeAfter.data.startsWith(' ');
|
150
|
+
let isInsertedInBrackets = false;
|
151
|
+
if (nodeBefore && nodeAfter && nodeBefore.is('$text') && nodeAfter.is('$text')) {
|
152
|
+
const precedingCharacter = nodeBefore.data.slice(-1);
|
153
|
+
const isPrecededByOpeningBracket = precedingCharacter in BRACKET_PAIRS;
|
154
|
+
const isFollowedByBracketClosure = isPrecededByOpeningBracket && nodeAfter.data.startsWith(BRACKET_PAIRS[precedingCharacter]);
|
155
|
+
isInsertedInBrackets = isPrecededByOpeningBracket && isFollowedByBracketClosure;
|
156
|
+
}
|
157
|
+
// Don't add a white space if either of the following is true:
|
158
|
+
// * there's already one after the mention;
|
159
|
+
// * the mention was inserted in the empty matching brackets.
|
160
|
+
// https://github.com/ckeditor/ckeditor5/issues/4651
|
161
|
+
if (!isInsertedInBrackets && !isFollowedByWhiteSpace) {
|
162
|
+
model.insertContent(writer.createText(' ', currentAttributes), range.start.getShiftedBy(mentionText.length));
|
163
|
+
}
|
143
164
|
});
|
144
165
|
}
|
145
166
|
}
|