Skip to content

Commit f013c2f

Browse files
authored
Fix buggy behavior of allowWhitespace (#85)
This should fix #84
1 parent e7d83b1 commit f013c2f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/List.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export default class List extends React.Component<ListProps, ListState> {
1111
selectedItem: null,
1212
};
1313

14+
cachedValues: ?string = null;
15+
1416
componentDidMount() {
1517
this.listeners.push(
1618
Listeners.add([KEY_CODES.DOWN, KEY_CODES.UP], this.scroll),
@@ -22,8 +24,12 @@ export default class List extends React.Component<ListProps, ListState> {
2224
}
2325

2426
componentWillReceiveProps({ values }: ListProps) {
25-
if (this.props.values !== values && values && values[0])
27+
const newValues = values.map(val => this.getId(val)).join('');
28+
29+
if (this.cachedValues !== newValues && values && values[0]) {
2630
this.selectItem(values[0]);
31+
this.cachedValues = newValues;
32+
}
2733
}
2834

2935
componentWillUnmount() {

src/Textarea.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,16 @@ class ReactTextareaAutocomplete extends React.Component<
160160
* It's important to escape the currentTrigger char for chars like [, (,...
161161
*/
162162
new RegExp(
163-
`\\${currentTrigger}${
164-
trigger[currentTrigger].allowWhitespace
165-
? '.'
166-
: `[^\\${currentTrigger}\\s]`
167-
}*$`
163+
`\\${currentTrigger}${`[^\\${currentTrigger}${
164+
trigger[currentTrigger].allowWhitespace ? '' : '\\s'
165+
}]`}*$`
168166
)
169167
);
170168

171169
// we add space after emoji is selected if a caret position is next
172170
const newTokenString =
173171
newToken.caretPosition === 'next' ? `${newToken.text} ` : newToken.text;
172+
174173
const newCaretPosition = computeCaretPosition(
175174
newToken.caretPosition,
176175
newTokenString,

0 commit comments

Comments
 (0)