File tree 3 files changed +19
-1
lines changed
frontend/src/components/composer
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 25
25
- update ` @deltachat/message_parser_wasm ` from ` 0.11.0 ` to ` 0.12.0 ` #4477
26
26
27
27
## Fixed
28
+ - fix draft not getting cleared after sending the message #
28
29
- fix chat "scrolls up" right after switching (rev 2) #4431
29
30
- when deleting a message from gallery, update gallery items to remove the respective item #4457
30
31
- accessibility: fix arrow-key navigation stopping working after ~ 10 key presses #4441
Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ export default class ComposerMessageInput extends React.Component<
49
49
this . insertStringAtCursorPosition =
50
50
this . insertStringAtCursorPosition . bind ( this )
51
51
52
+ // Remember that the draft might be updated from the outside
53
+ // of this component (with the `setText` method,
54
+ // e.g. when the draft gets cleared after sending a message).
55
+ // This can happen _after_ an `onChange` event but _before_
56
+ // the unrelying throttled function invokation.
52
57
this . throttledSaveDraft = throttle ( ( text , chatId ) => {
53
58
if ( this . state . chatId === chatId ) {
54
59
this . props . updateDraftText ( text . trim ( ) === '' ? '' : text , chatId )
@@ -77,8 +82,16 @@ export default class ComposerMessageInput extends React.Component<
77
82
return null
78
83
}
79
84
85
+ /**
86
+ * Sets the text area value, and ensures that `updateDraftText`
87
+ * does not get invoked until the next change to the draft text.
88
+ *
89
+ * Useful for setting / clearing draft text afer loading it from core,
90
+ * e.g. after sending the message or opening a chat with a.
91
+ */
80
92
setText ( text : string | null ) {
81
93
this . setState ( { text : text || '' , loadingDraft : false } )
94
+ this . throttledSaveDraft . cancel ( )
82
95
}
83
96
84
97
setComposerSize ( size : number ) {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ export function throttle<R, A extends any[]>(
22
22
let inThrottle : boolean ,
23
23
timeout : ReturnType < typeof setTimeout > ,
24
24
lastTime : number
25
- return ( ...args : A ) => {
25
+ const ret = ( ...args : A ) => {
26
26
if ( ! inThrottle ) {
27
27
fn ( ...args )
28
28
lastTime = performance . now ( )
@@ -38,4 +38,8 @@ export function throttle<R, A extends any[]>(
38
38
)
39
39
}
40
40
}
41
+ ret . cancel = ( ) => {
42
+ clearTimeout ( timeout )
43
+ }
44
+ return ret
41
45
}
You can’t perform that action at this time.
0 commit comments