From a9af3a8928e6eb36b313e96c2a0e9eafecfd5b7f Mon Sep 17 00:00:00 2001 From: crockwave Date: Wed, 6 May 2020 18:58:21 -0500 Subject: [PATCH 1/3] Allow cursor to be rendered at end of textbox by commenting out date comparison conditional --- .gitignore | 2 ++ app/gabsocial/features/compose/components/compose_form.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e146e98fa..6964989f1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /.eslintcache /.env /deploy.sh +/.vs/slnx.sqlite +/.vs/slnx.sqlite-journal diff --git a/app/gabsocial/features/compose/components/compose_form.js b/app/gabsocial/features/compose/components/compose_form.js index acb21f5fd..8888c1a38 100644 --- a/app/gabsocial/features/compose/components/compose_form.js +++ b/app/gabsocial/features/compose/components/compose_form.js @@ -180,7 +180,7 @@ class ComposeForm extends ImmutablePureComponent { // - Replying to zero or one users, places the cursor at the end of the textbox. // - Replying to more than one user, selects any usernames past the first; // this provides a convenient shortcut to drop everyone else from the conversation. - if (this.props.focusDate !== prevProps.focusDate) { + //if (this.props.focusDate !== prevProps.focusDate) { let selectionEnd, selectionStart; if (this.props.preselectDate !== prevProps.preselectDate) { @@ -196,7 +196,7 @@ class ComposeForm extends ImmutablePureComponent { this.autosuggestTextarea.textarea.setSelectionRange(selectionStart, selectionEnd); this.autosuggestTextarea.textarea.focus(); - } + //} } setAutosuggestTextarea = (c) => { From f1747f4425da112185c5389038e7caa1fc101307 Mon Sep 17 00:00:00 2001 From: crockwave Date: Fri, 8 May 2020 17:14:07 -0500 Subject: [PATCH 2/3] Allow cursor to render at end of textbox to only place at end on new load, and bug fixes of cursor placement problems when selecting text and or moving cursor to left and typing --- .gitignore | 3 +- app/gabsocial/actions/compose.js | 2 +- .../components/autosuggest_textarea.js | 1 - .../compose/components/compose_form.js | 28 +++++++++++-------- app/gabsocial/reducers/compose.js | 3 +- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 6964989f1..da7dcee8d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ /.eslintcache /.env /deploy.sh -/.vs/slnx.sqlite -/.vs/slnx.sqlite-journal +/.vs/ diff --git a/app/gabsocial/actions/compose.js b/app/gabsocial/actions/compose.js index 5a9de9051..0c9939bb0 100644 --- a/app/gabsocial/actions/compose.js +++ b/app/gabsocial/actions/compose.js @@ -73,7 +73,7 @@ export const ensureComposeIsVisible = (getState, routerHistory) => { } }; -export function changeCompose(text) { +export function changeCompose(text, caretPosition) { return { type: COMPOSE_CHANGE, text: text, diff --git a/app/gabsocial/components/autosuggest_textarea.js b/app/gabsocial/components/autosuggest_textarea.js index cae6116d4..a9fc1f6ad 100644 --- a/app/gabsocial/components/autosuggest_textarea.js +++ b/app/gabsocial/components/autosuggest_textarea.js @@ -74,7 +74,6 @@ export default class AutosuggestTextarea extends ImmutablePureComponent { this.setState({ lastToken: null }); this.props.onSuggestionsClearRequested(); } - this.props.onChange(e); } diff --git a/app/gabsocial/features/compose/components/compose_form.js b/app/gabsocial/features/compose/components/compose_form.js index 8888c1a38..7e0e18b27 100644 --- a/app/gabsocial/features/compose/components/compose_form.js +++ b/app/gabsocial/features/compose/components/compose_form.js @@ -44,6 +44,7 @@ class ComposeForm extends ImmutablePureComponent { state = { composeFocused: false, + caretPosition: 0, } static contextTypes = { @@ -86,6 +87,9 @@ class ComposeForm extends ImmutablePureComponent { handleChange = (e) => { this.props.onChange(e.target.value); + this.setState({ + caretPosition: e.target.selectionStart, + }); } handleComposeFocus = () => { @@ -180,23 +184,25 @@ class ComposeForm extends ImmutablePureComponent { // - Replying to zero or one users, places the cursor at the end of the textbox. // - Replying to more than one user, selects any usernames past the first; // this provides a convenient shortcut to drop everyone else from the conversation. - //if (this.props.focusDate !== prevProps.focusDate) { - let selectionEnd, selectionStart; + let selectionEnd, selectionStart; + if (this.props.focusDate !== prevProps.focusDate) { if (this.props.preselectDate !== prevProps.preselectDate) { - selectionEnd = this.props.text.length; + selectionEnd = this.props.text.length; selectionStart = this.props.text.search(/\s/) + 1; - } else if (typeof this.props.caretPosition === 'number') { - selectionStart = this.props.caretPosition; - selectionEnd = this.props.caretPosition; - } else { - selectionEnd = this.props.text.length; - selectionStart = selectionEnd; + } else if (typeof this.state.caretPosition === 'number') { + selectionStart = this.state.caretPosition; + selectionEnd = this.state.caretPosition; } - this.autosuggestTextarea.textarea.setSelectionRange(selectionStart, selectionEnd); this.autosuggestTextarea.textarea.focus(); - //} + } else { + if (this.props.preselectDate !== this.props.focusDate) { + selectionStart = selectionEnd = this.props.text.length + 1; + this.autosuggestTextarea.textarea.setSelectionRange(selectionStart, selectionEnd); + this.autosuggestTextarea.textarea.focus(); + } + } } setAutosuggestTextarea = (c) => { diff --git a/app/gabsocial/reducers/compose.js b/app/gabsocial/reducers/compose.js index 930909a3b..d7a9e5613 100644 --- a/app/gabsocial/reducers/compose.js +++ b/app/gabsocial/reducers/compose.js @@ -237,7 +237,8 @@ export default function compose(state = initialState, action) { case COMPOSE_CHANGE: return state .set('text', action.text) - .set('idempotencyKey', uuid()); + .set('idempotencyKey', uuid()) + .set('focusDate', new Date()); case COMPOSE_COMPOSING_CHANGE: return state.set('is_composing', action.value); case COMPOSE_REPLY: From b35122e75c2b88c6bc25e40dc4e6a33a5ce49102 Mon Sep 17 00:00:00 2001 From: crockwave Date: Fri, 8 May 2020 17:40:54 -0500 Subject: [PATCH 3/3] Cleaned up unrequired code changes --- app/gabsocial/actions/compose.js | 2 +- app/gabsocial/components/autosuggest_textarea.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/gabsocial/actions/compose.js b/app/gabsocial/actions/compose.js index 0c9939bb0..5a9de9051 100644 --- a/app/gabsocial/actions/compose.js +++ b/app/gabsocial/actions/compose.js @@ -73,7 +73,7 @@ export const ensureComposeIsVisible = (getState, routerHistory) => { } }; -export function changeCompose(text, caretPosition) { +export function changeCompose(text) { return { type: COMPOSE_CHANGE, text: text, diff --git a/app/gabsocial/components/autosuggest_textarea.js b/app/gabsocial/components/autosuggest_textarea.js index a9fc1f6ad..cae6116d4 100644 --- a/app/gabsocial/components/autosuggest_textarea.js +++ b/app/gabsocial/components/autosuggest_textarea.js @@ -74,6 +74,7 @@ export default class AutosuggestTextarea extends ImmutablePureComponent { this.setState({ lastToken: null }); this.props.onSuggestionsClearRequested(); } + this.props.onChange(e); }