@@ -40,6 +40,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
4040 private removeNextReplyBoxBorders = false ;
4141 private lastSwitchToEncryptedReply = false ;
4242 private replyOption : ReplyOption | undefined ;
43+ private lastReplyOption : ReplyOption | undefined ;
4344
4445 private sel = {
4546 // gmail_variant=standard|new
@@ -642,6 +643,8 @@ export class GmailElementReplacer extends WebmailElementReplacer {
642643 const legacyDraftReplyRegex = new RegExp ( / \[ ( f l o w c r y p t | c r y p t u p ) : l i n k : d r a f t _ r e p l y : ( [ 0 - 9 a - f r \- ] + ) ] / ) ;
643644 const newReplyBoxes = $ ( 'div.nr.tMHS5d, td.amr > div.nr, div.gA td.I5' ) . not ( '.reply_message_evaluated' ) . filter ( ':visible' ) . get ( ) ;
644645 if ( newReplyBoxes . length ) {
646+ // removing this line will cause unexpected draft creation bug reappear
647+ // https://github.com/FlowCrypt/flowcrypt-browser/issues/5616#issuecomment-1972897692
645648 this . replyOption = undefined ;
646649 // cache for subseqent loop runs
647650 const convoRootEl = this . getConvoRootEl ( newReplyBoxes [ 0 ] ) ;
@@ -688,6 +691,10 @@ export class GmailElementReplacer extends WebmailElementReplacer {
688691 const replyOption = this . parseReplyOption ( replyBox ) ;
689692 if ( replyOption ) {
690693 this . replyOption = replyOption ;
694+ this . lastReplyOption = replyOption ;
695+ } else if ( this . lastReplyOption ) {
696+ this . replyOption = this . lastReplyOption ;
697+ this . lastReplyOption = undefined ;
691698 }
692699 replyParams . replyOption = this . replyOption ;
693700 // either is a draft in the middle, or the convo already had (last) box replaced: should also be useless draft
@@ -708,8 +715,10 @@ export class GmailElementReplacer extends WebmailElementReplacer {
708715 if ( hasDraft || alreadyHasSecureReplyBox ) {
709716 replyBox . addClass ( 'reply_message_evaluated remove_borders' ) . parent ( ) . append ( secureReplyBoxXssSafe ) ; // xss-safe-factory
710717 replyBox . hide ( ) ;
718+ this . lastReplyOption = undefined ;
711719 } else if ( isReplyButtonView ) {
712720 replyBox . replaceWith ( secureReplyBoxXssSafe ) ; // xss-safe-factory
721+ this . lastReplyOption = undefined ;
713722 this . replyOption = undefined ;
714723 } else {
715724 const deleteReplyEl = document . querySelector ( '.oh.J-Z-I.J-J5-Ji.T-I-ax7' ) ;
0 commit comments