Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit d927642

Browse files
authored
When showing thread, always auto-focus its composer (#8115)
1 parent a8d65ab commit d927642

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

src/components/views/messages/MessageActionBar.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
2424
import type { Relations } from 'matrix-js-sdk/src/models/relations';
2525
import { _t } from '../../../languageHandler';
2626
import dis from '../../../dispatcher/dispatcher';
27-
import { Action } from '../../../dispatcher/actions';
2827
import ContextMenu, { aboveLeftOf, ContextMenuTooltipButton, useContextMenu } from '../../structures/ContextMenu';
2928
import { isContentActionable, canEditContent, editEvent } from '../../../utils/EventUtils';
3029
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
@@ -225,10 +224,6 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
225224

226225
private onThreadClick = (isCard: boolean): void => {
227226
showThread({ rootEvent: this.props.mxEvent, push: isCard });
228-
dis.dispatch({
229-
action: Action.FocusSendMessageComposer,
230-
context: TimelineRenderingType.Thread,
231-
});
232227
};
233228

234229
private onEditClick = (): void => {

src/components/views/rooms/EditMessageComposer.tsx

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,27 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
202202
timelineRenderingType: this.context.timelineRenderingType,
203203
});
204204
} else {
205-
this.clearStoredEditorState();
206-
dis.dispatch({
207-
action: Action.EditEvent,
208-
event: null,
209-
timelineRenderingType: this.context.timelineRenderingType,
210-
});
211-
dis.dispatch({
212-
action: Action.FocusSendMessageComposer,
213-
context: this.context.timelineRenderingType,
214-
});
205+
this.cancelEdit();
215206
}
216207
event.preventDefault();
217208
break;
218209
}
219210
}
220211
};
221212

213+
private endEdit(): void {
214+
// close the event editing and focus composer
215+
dis.dispatch({
216+
action: Action.EditEvent,
217+
event: null,
218+
timelineRenderingType: this.context.timelineRenderingType,
219+
});
220+
dis.dispatch({
221+
action: Action.FocusSendMessageComposer,
222+
context: this.context.timelineRenderingType,
223+
});
224+
}
225+
222226
private get editorRoomKey(): string {
223227
return `mx_edit_room_${this.getRoom().roomId}_${this.context.timelineRenderingType}`;
224228
}
@@ -236,15 +240,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
236240

237241
private cancelEdit = (): void => {
238242
this.clearStoredEditorState();
239-
dis.dispatch({
240-
action: Action.EditEvent,
241-
event: null,
242-
timelineRenderingType: this.context.timelineRenderingType,
243-
});
244-
dis.dispatch({
245-
action: Action.FocusSendMessageComposer,
246-
context: this.context.timelineRenderingType,
247-
});
243+
this.endEdit();
248244
};
249245

250246
private get shouldSaveStoredEditorState(): boolean {
@@ -357,16 +353,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
357353
}
358354
}
359355

360-
// close the event editing and focus composer
361-
dis.dispatch({
362-
action: Action.EditEvent,
363-
event: null,
364-
timelineRenderingType: this.context.timelineRenderingType,
365-
});
366-
dis.dispatch({
367-
action: Action.FocusSendMessageComposer,
368-
context: this.context.timelineRenderingType,
369-
});
356+
this.endEdit();
370357
};
371358

372359
private cancelPreviousPendingEdit(): void {

src/dispatcher/dispatch-actions/threads.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
1718

1819
import RightPanelStore from "../../stores/right-panel/RightPanelStore";
1920
import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases";
21+
import dis from "../dispatcher";
22+
import { Action } from "../actions";
23+
import { TimelineRenderingType } from "../../contexts/RoomContext";
2024

2125
export const showThread = (props: {
2226
rootEvent: MatrixEvent;
@@ -41,6 +45,12 @@ export const showThread = (props: {
4145
threadViewCard,
4246
]);
4347
}
48+
49+
// Focus the composer
50+
dis.dispatch({
51+
action: Action.FocusSendMessageComposer,
52+
context: TimelineRenderingType.Thread,
53+
});
4454
};
4555

4656
export const showThreadPanel = () => {

0 commit comments

Comments
 (0)