diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-05-22 21:09:07 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-05-26 12:17:03 +0200 |
commit | 18d9a7fd718f8c56f2680057fbed5b550e748b0d (patch) | |
tree | 6ee622a43c4d8f40fa6bdf615e1d0263921010ab /app/javascript/flavours/glitch/features/composer | |
parent | d8793e1bee742c8104efbe1c9d28915ab000248e (diff) |
Fix caret position after inserting suggestions (fixes #281)
Diffstat (limited to 'app/javascript/flavours/glitch/features/composer')
-rw-r--r-- | app/javascript/flavours/glitch/features/composer/index.js | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/app/javascript/flavours/glitch/features/composer/index.js b/app/javascript/flavours/glitch/features/composer/index.js index c9e2d62b0..21b03be39 100644 --- a/app/javascript/flavours/glitch/features/composer/index.js +++ b/app/javascript/flavours/glitch/features/composer/index.js @@ -56,6 +56,7 @@ function mapStateToProps (state) { advancedOptions: state.getIn(['compose', 'advanced_options']), amUnlocked: !state.getIn(['accounts', me, 'locked']), focusDate: state.getIn(['compose', 'focusDate']), + caretPosition: state.getIn(['compose', 'caretPosition']), isSubmitting: state.getIn(['compose', 'is_submitting']), isUploading: state.getIn(['compose', 'is_uploading']), layout: state.getIn(['local_settings', 'layout']), @@ -117,7 +118,6 @@ const handlers = { handleEmoji (data) { const { textarea: { selectionStart } } = this; const { onInsertEmoji } = this.props; - this.caretPos = selectionStart + data.native.length + 1; if (onInsertEmoji) { onInsertEmoji(selectionStart, data); } @@ -139,7 +139,6 @@ const handlers = { // Selects a suggestion from the autofill. handleSelect (tokenStart, token, value) { const { onSelectSuggestion } = this.props; - this.caretPos = null; if (onSelectSuggestion) { onSelectSuggestion(tokenStart, token, value); } @@ -191,7 +190,6 @@ class Composer extends React.Component { assignHandlers(this, handlers); // Instance variables. - this.caretPos = null; this.textarea = null; } @@ -220,11 +218,11 @@ class Composer extends React.Component { // everyone else from the conversation. componentDidUpdate (prevProps) { const { - caretPos, textarea, } = this; const { focusDate, + caretPosition, isSubmitting, preselectDate, text, @@ -238,8 +236,8 @@ class Composer extends React.Component { selectionStart = text.search(/\s/) + 1; selectionEnd = text.length; break; - case !isNaN(caretPos) && caretPos !== null: - selectionStart = selectionEnd = caretPos; + case !isNaN(caretPosition) && caretPosition !== null: + selectionStart = selectionEnd = caretPosition; break; default: selectionStart = selectionEnd = text.length; @@ -396,6 +394,7 @@ Composer.propTypes = { advancedOptions: ImmutablePropTypes.map, amUnlocked: PropTypes.bool, focusDate: PropTypes.instanceOf(Date), + caretPosition: PropTypes.number, isSubmitting: PropTypes.bool, isUploading: PropTypes.bool, layout: PropTypes.string, |