Prevent composer body/sig/quote parts from losing focus. Bug 779369.

* ui/composer-web-view.js: Add a click handler for the document that
  prevents clicks outside the body parts from being processed.
This commit is contained in:
Michael James Gratton 2017-11-16 15:49:51 +11:00
parent 343bb640e9
commit 261e8a4ba3

View file

@ -59,7 +59,19 @@ ComposerPageState.prototype = {
let state = this;
this.bodyPart = document.getElementById("geary-body");
if (this.bodyPart == null) {
if (this.bodyPart != null) {
// Capture clicks on the document that aren't on an
// existing part and prevent focus leaving it. Bug 779369.
document.addEventListener("mousedown", function(e) {
if (!state.containedInPart(e.target)) {
e.preventDefault();
e.stopPropagation();
}
});
} else {
// This happens if we are loading a draft created by a MUA
// that isn't Geary, so we can't rely on any of the
// expected HTML structure to be in place.
this.bodyPart = document.body;
}
@ -381,6 +393,16 @@ ComposerPageState.prototype = {
this.focusedPart = newFocus;
this.focusedPart.classList.add("geary-focus");
}
},
containedInPart: function(target) {
let inPart = false;
for (let part of [this.bodyPart, this.quotePart, this.signaturePart]) {
if (part != null && (part == target || part.contains(target))) {
inPart = true;
break;
}
}
return inPart;
}
};