Skip to content

Commit 72f8baf

Browse files
author
Benjamin Kniffler
committed
Merge branch 'master' into wysiwyg
2 parents d925052 + 74e6fab commit 72f8baf

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

draft-js-emoji-plugin/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
### Changed
99

1010
- Move to a flat configuration. Instead of plugin properties (decorators & hooks) being stored within pluginProps they now moved to the root object. See the changes here [#150](https://github.com/draft-js-plugins/draft-js-plugins/pull/150/files) as well as the initial discussion here [#143](https://github.com/draft-js-plugins/draft-js-plugins/issues/143)
11+
- Improved the regex and now test for a whitespace in front of the `:` to make sure it doesn't match on normal text like a link [#104](https://github.com/draft-js-plugins/draft-js-plugins/issues/104)
12+
13+
### Fixed
14+
15+
- Fix using backspace to close the autocomplete suggestions after typing a `:` [#153](https://github.com/draft-js-plugins/draft-js-plugins/issues/153)
1116

1217
## 0.0.4 - 2016-03-29
1318

draft-js-emoji-plugin/src/EmojiSearch/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ export default class EmojiSearch extends Component {
6060

6161
// identify the start & end positon of the search-text
6262
const { blockKey, decoratorKey, leafKey } = decodeOffsetKey(this.props.offsetKey);
63-
const { start, end } = editorState
63+
64+
const leave = editorState
6465
.getBlockTree(blockKey)
6566
.getIn([decoratorKey, 'leaves', leafKey]);
6667

68+
// the leave can be empty when it is removed due e.g. using backspace
69+
if (leave === undefined) {
70+
return editorState;
71+
}
72+
73+
const { start, end } = leave;
74+
6775
// get the current selection
6876
const selection = editorState.getSelection();
6977

draft-js-emoji-plugin/src/emojiSearchStrategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import findWithRegex from 'find-with-regex';
44

5-
const EMOJI_REGEX = /:[\w]*/g;
5+
const EMOJI_REGEX = /(\s|^):[\w]*/g;
66

77
export default (contentBlock: Object, callback: Function) => {
88
findWithRegex(EMOJI_REGEX, contentBlock, callback);

draft-js-mention-plugin/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
### Changed
99

1010
- Move to a flat configuration. Instead of plugin properties (decorators & hooks) being stored within pluginProps they now moved to the root object. See the changes here [#150](https://github.com/draft-js-plugins/draft-js-plugins/pull/150/files) as well as the initial discussion here [#143](https://github.com/draft-js-plugins/draft-js-plugins/issues/143)
11+
- Improved the regex and now test for a whitespace in front of the `@` to make sure it doesn't match on normal text like an email [#104](https://github.com/draft-js-plugins/draft-js-plugins/issues/104)
12+
13+
### Fixed
14+
15+
- Fix using backspace to close the autocomplete suggestions after typing an `@` [#110](https://github.com/draft-js-plugins/draft-js-plugins/issues/110)
1116

1217
## 0.0.4 - 2016-03-29
1318

draft-js-mention-plugin/src/MentionSearch/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ export default class MentionSearch extends Component {
5555

5656
// identify the start & end positon of the search-text
5757
const { blockKey, decoratorKey, leafKey } = decodeOffsetKey(this.props.offsetKey);
58-
const { start, end } = editorState
58+
59+
// the leave can be empty when it is removed due e.g. using backspace
60+
const leave = editorState
5961
.getBlockTree(blockKey)
6062
.getIn([decoratorKey, 'leaves', leafKey]);
63+
if (leave === undefined) {
64+
return editorState;
65+
}
66+
67+
const { start, end } = leave;
6168

6269
// get the current selection
6370
const selection = editorState.getSelection();

draft-js-mention-plugin/src/mentionSearchStrategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import findWithRegex from 'find-with-regex';
44

5-
const MENTION_REGEX = /\@[\w]*/g;
5+
const MENTION_REGEX = /(\s|^)\@[\w]*/g;
66

77
export default (contentBlock: Object, callback: Function) => {
88
findWithRegex(MENTION_REGEX, contentBlock, callback);

draft-js-plugins-editor/src/Editor/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,38 @@ class PluginEditor extends Component {
9292

9393
createPluginHooks = () => {
9494
const pluginHooks = {};
95+
const eventHookKeys = [];
96+
const fnHookKeys = [];
9597
const plugins = this.resolvePlugins();
9698

9799
plugins.forEach((plugin) => {
98100
Object.keys(plugin).forEach((attrName) => {
99101
if (attrName === 'onChange') return;
100102

101-
if (attrName.indexOf('on') === 0 || attrName.indexOf('handle') === 0) {
102-
pluginHooks[attrName] = this.createEventHooks(attrName, plugins);
103+
// if `attrName` has been added as a hook key already, ignore this one
104+
if (eventHookKeys.indexOf(attrName) !== -1 || fnHookKeys.indexOf(attrName) !== -1) return;
105+
106+
const isEventHookKey = attrName.indexOf('on') === 0 || attrName.indexOf('handle') === 0;
107+
if (isEventHookKey) {
108+
eventHookKeys.push(attrName);
109+
return;
103110
}
104111

105-
// checks if the function ends with Fn
106-
if (attrName.length - 2 === attrName.indexOf('Fn')) {
107-
pluginHooks[attrName] = this.createFnHooks(attrName, plugins);
112+
// checks if `attrName` ends with 'Fn'
113+
const isFnHookKey = (attrName.length - 2 === attrName.indexOf('Fn'));
114+
if (isFnHookKey) {
115+
fnHookKeys.push(attrName);
108116
}
109117
});
110118
});
119+
120+
eventHookKeys.forEach((attrName) => {
121+
pluginHooks[attrName] = this.createEventHooks(attrName, plugins);
122+
});
123+
fnHookKeys.forEach((attrName) => {
124+
pluginHooks[attrName] = this.createFnHooks(attrName, plugins);
125+
});
126+
111127
return pluginHooks;
112128
};
113129

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"find-with-regex": "^1.0.2",
9494
"immutable": "^3.7.6",
9595
"linkify-it": "1.2.0",
96+
"loader-utils": "^0.2.13",
9697
"tlds": "1.99.0",
9798
"union-class-names": "^1.0.0",
9899
"webpack": "^1.12.14"

0 commit comments

Comments
 (0)