Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autofocus the compose form again on /share #23094

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

Akkiesoft
Copy link
Contributor

After merging #16517 , compose form on /share does not work autofocus so I fix it.

@@ -153,7 +153,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 && this.props.focusDate !== prevProps.focusDate) {
if ((this.props.focusDate && this.props.focusDate !== prevProps.focusDate) || this.props.autoFocus) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added because the /share compose form also needs to move the cursor to the end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is called from componentDidUpdate as well, this will set the focus and selection to the very end of the textarea for every compose state change, including every keypress in either the textarea or the CW field. I would suggest setting the focusDate through a new action instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set focusDate in app/javascript/mastodon/reducers/compose.js instead of this change. How about it?
(Sorry, I am not familiar with the React...)

@@ -9,7 +9,7 @@ export default class Compose extends React.PureComponent {
render () {
return (
<div>
<ComposeFormContainer />
<ComposeFormContainer autoFocus />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -153,7 +153,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 && this.props.focusDate !== prevProps.focusDate) {
if ((this.props.focusDate && this.props.focusDate !== prevProps.focusDate) || this.props.autoFocus) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is called from componentDidUpdate as well, this will set the focus and selection to the very end of the textarea for every compose state change, including every keypress in either the textarea or the CW field. I would suggest setting the focusDate through a new action instead.

Comment on lines 225 to 231
if (hydratedState.has('text')) {
state = state.set('text', hydratedState.get('text'));
const text = hydratedState.get('text');
if (text) {
state = state
.set('text', hydratedState.get('text'))
.set('focusDate', new Date());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's actually a good way to do it!

Code-style wise, I'd do something like this though:

Suggested change
if (hydratedState.has('text')) {
state = state.set('text', hydratedState.get('text'));
const text = hydratedState.get('text');
if (text) {
state = state
.set('text', hydratedState.get('text'))
.set('focusDate', new Date());
}
if (hydratedState.get('text')) {
state = state.set('text', hydratedState.get('text')).set('focusDate', new Date());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice. I've pushed the commit again :)

@@ -223,7 +223,7 @@ const hydrate = (state, hydratedState) => {
state = clearAll(state.merge(hydratedState));

if (hydratedState.has('text')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it should be hydratedState.get('text'): indeed, the normal interface has a text key with an empty value… which means the change as-is would make the single-column interface back to having auto-focus on the form despite the intent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed that...

@ClearlyClaire ClearlyClaire merged commit e73b551 into mastodon:main Jan 30, 2023
@Akkiesoft Akkiesoft deleted the share-autofocus branch January 31, 2023 08:37
btrd pushed a commit to btrd/mastodon that referenced this pull request Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants