gmail.js icon indicating copy to clipboard operation
gmail.js copied to clipboard

Close the reply or forward section using compose.close()

Open SanketDG opened this issue 6 years ago • 3 comments

When I have a compose reference, I can close the compose window compose.close(), when the same compose instance has a reply or forward type, it is not closed or the section is not removed. Is there any other way I can achieve this?

SanketDG avatar Aug 28 '19 08:08 SanketDG

Sounds like a bug. If you have time, I suggest you try to debug why it works on one compose-type, but not the others.

This is a low-activity, few-maintainer project and the definite best way to get things fixed around here, is contributing PRs.

josteink avatar Aug 28 '19 10:08 josteink

Sounds like a bug. If you have time, I suggest you try to debug why it works on one compose-type, but not the others.

Sure, took a look into this.

Apparently, the inline compose (the compose box that appears when replying or forwarding to a mail), cannot be closed with Esc, which works for the popout compose box.

Instead, I had to rely on a specific kind of keyboard shortcut hack, where Ctrl+Shift+D discards the d raft, and puts a "Draft discarded" toast. The following code below emulates and fires that keyboard event on the textbox, and removes the toast from the DOM, using a timer. This is not the best approach, but it works for me now!

if(compose_ref.is_inline()) {
  const keyboard_event = document.createEvent('Event');
  keyboard_event.initEvent('keydown', true, true);
  keyboard_event.which = 68;
  keyboard_event.shiftKey = true;
  keyboard_event.ctrlKey = true;
  keyboard_event.keyCode = 68;

  let draft_compose = document.getElementsByClassName("Am aO9 Al editable LW-avf")[0];
  draft_compose.focus();
  draft_compose.dispatchEvent(keyboard_event);

  let notificationClear = setInterval(()=>{
    let notificationDOM = document.getElementsByClassName("vh");
    if(notificationDOM.length !== 0) {
      notificationDOM[0].remove();
      clearInterval(notificationClear);
    }
  }, 500);
}

Let me know if you want this integrated.

SanketDG avatar Aug 29 '19 11:08 SanketDG

I’ve seen worse :smile:

If it makes the overall API work more as intended, that’s completely legit.

Only thing I’d appreciate is if you manage to chug a nice summary of what and why you are doing these things into the code as comments.

Sounds good?

josteink avatar Aug 29 '19 18:08 josteink