Merge remote-tracking branch 'origin/develop' into snackbar
This commit is contained in:
commit
a999c5d8ce
2 changed files with 23 additions and 29 deletions
|
@ -50,8 +50,6 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
|
||||||
autoFocus: PropTypes.bool,
|
autoFocus: PropTypes.bool,
|
||||||
onFocus: PropTypes.func,
|
onFocus: PropTypes.func,
|
||||||
onBlur: PropTypes.func,
|
onBlur: PropTypes.func,
|
||||||
clickableAreaRef: PropTypes.object,
|
|
||||||
getClickableArea: PropTypes.func.isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
@ -109,8 +107,6 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
|
||||||
if (suggestions.size > 0 && !suggestionsHidden) {
|
if (suggestions.size > 0 && !suggestionsHidden) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.setState({ selectedSuggestion: Math.min(selectedSuggestion + 1, suggestions.size - 1) });
|
this.setState({ selectedSuggestion: Math.min(selectedSuggestion + 1, suggestions.size - 1) });
|
||||||
} else {
|
|
||||||
this.setState({ lastToken: null });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -118,8 +114,6 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
|
||||||
if (suggestions.size > 0 && !suggestionsHidden) {
|
if (suggestions.size > 0 && !suggestionsHidden) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.setState({ selectedSuggestion: Math.max(selectedSuggestion - 1, 0) });
|
this.setState({ selectedSuggestion: Math.max(selectedSuggestion - 1, 0) });
|
||||||
} else {
|
|
||||||
this.setState({ lastToken: null });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -165,27 +159,19 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
|
||||||
this.textarea.focus();
|
this.textarea.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
isClickInside = (e) => {
|
shouldComponentUpdate(nextProps, nextState) {
|
||||||
return [
|
// Skip updating when only the lastToken changes so the
|
||||||
this.props.getClickableArea(),
|
// cursor doesn't jump around due to re-rendering unnecessarily
|
||||||
document.querySelector('.autosuggest-textarea__textarea'),
|
const lastTokenUpdated = this.state.lastToken !== nextState.lastToken;
|
||||||
].some(element => element && element.contains(e.target));
|
const valueUpdated = this.props.value !== nextProps.value;
|
||||||
}
|
|
||||||
|
|
||||||
handleClick = (e) => {
|
if (lastTokenUpdated && !valueUpdated) {
|
||||||
if (this.isClickInside(e)) {
|
return false;
|
||||||
this.setState({ lastToken: null });
|
} else {
|
||||||
|
return super.shouldComponentUpdate(nextProps, nextState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
document.addEventListener('click', this.handleClick, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
document.removeEventListener('click', this.handleClick, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
const { suggestions } = this.props;
|
const { suggestions } = this.props;
|
||||||
if (suggestions !== prevProps.suggestions && suggestions.size > 0 && prevState.suggestionsHidden && prevState.focused) {
|
if (suggestions !== prevProps.suggestions && suggestions.size > 0 && prevState.suggestionsHidden && prevState.focused) {
|
||||||
|
|
|
@ -160,11 +160,6 @@ class ComposeForm extends ImmutablePureComponent {
|
||||||
this.props.onChangeSpoilerText(e.target.value);
|
this.props.onChangeSpoilerText(e.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
doFocus = () => {
|
|
||||||
if (!this.autosuggestTextarea) return;
|
|
||||||
this.autosuggestTextarea.textarea.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
setCursor = (start, end = start) => {
|
setCursor = (start, end = start) => {
|
||||||
if (!this.autosuggestTextarea) return;
|
if (!this.autosuggestTextarea) return;
|
||||||
this.autosuggestTextarea.textarea.setSelectionRange(start, end);
|
this.autosuggestTextarea.textarea.setSelectionRange(start, end);
|
||||||
|
@ -219,8 +214,22 @@ class ComposeForm extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybeUpdateCursor = prevProps => {
|
||||||
|
const shouldUpdate = [
|
||||||
|
// Autosuggest has been updated and
|
||||||
|
// the cursor position explicitly set
|
||||||
|
this.props.focusDate !== prevProps.focusDate,
|
||||||
|
typeof this.props.caretPosition === 'number',
|
||||||
|
].every(Boolean);
|
||||||
|
|
||||||
|
if (shouldUpdate) {
|
||||||
|
this.setCursor(this.props.caretPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
this.maybeUpdateFocus(prevProps);
|
this.maybeUpdateFocus(prevProps);
|
||||||
|
this.maybeUpdateCursor(prevProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -286,7 +295,6 @@ class ComposeForm extends ImmutablePureComponent {
|
||||||
onSuggestionSelected={this.onSuggestionSelected}
|
onSuggestionSelected={this.onSuggestionSelected}
|
||||||
onPaste={onPaste}
|
onPaste={onPaste}
|
||||||
autoFocus={shouldAutoFocus}
|
autoFocus={shouldAutoFocus}
|
||||||
getClickableArea={this.getClickableArea}
|
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
!condensed &&
|
!condensed &&
|
||||||
|
|
Loading…
Reference in a new issue