[geary/wip/geary-is-descendant-of: 3/3] Fix select-quoting not preserving newlines in some cases
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/geary-is-descendant-of: 3/3] Fix select-quoting not preserving newlines in some cases
- Date: Sat, 2 Feb 2019 03:56:57 +0000 (UTC)
commit 6d96fee5d0775300c1943d9222c870695fdab062
Author: Michael Gratton <mike vee net>
Date: Sat Feb 2 14:48:22 2019 +1100
Fix select-quoting not preserving newlines in some cases
If the common ancestor of the quoted text is the plain-text-message DIV
itself, the isDescendant test fails and the style to preserve new lines
is not maintained. This adds a non-strict check to isDescendant and
enables that when checking the common ancestor node.
ui/conversation-web-view.js | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
---
diff --git a/ui/conversation-web-view.js b/ui/conversation-web-view.js
index fb6d9aca..ef209223 100644
--- a/ui/conversation-web-view.js
+++ b/ui/conversation-web-view.js
@@ -201,12 +201,15 @@ ConversationPageState.prototype = {
ancestor = ancestor.parentNode;
}
- // If the selection is part of a plain text message,
- // we have to stick it in an appropriately styled div,
- // so that new lines are preserved.
+ // If the selection is part of a plain text message, we
+ // have to stick it in an appropriately styled div, so
+ // that new lines are preserved. Do a non-strict ancestor
+ // check since the common ancestor may well be the plain
+ // text DIV itself
let dummy = document.createElement("DIV");
let includeDummy = false;
- if (ConversationPageState.isDescendantOf(ancestor, "DIV", "plaintext")) {
+ if (ConversationPageState.isDescendantOf(
+ ancestor, "DIV", "plaintext", false)) {
dummy.classList.add("plaintext");
dummy.setAttribute("style", "white-space: pre-wrap;");
includeDummy = true;
@@ -324,17 +327,21 @@ ConversationPageState.isDeceptiveText = function(text, href) {
/**
* See if this element has an ancestor with the given tag and class.
*
- * ancestorTag must be all uppercase.
+ * The value of ancestorTag must be all uppercase.
*
* If ancestorClass is null, no class checking is done.
+ * If strict is is true, the given node will not be checked.
*/
-ConversationPageState.isDescendantOf = function(node, ancestorTag, ancestorClass = null) {
- let ancestor = node.parentNode;
+ConversationPageState.isDescendantOf = function(node,
+ ancestorTag,
+ ancestorClass = null,
+ strict = true) {
+ let ancestor = strict ? node.parentNode : node;
while (ancestor != null) {
- if (ancestor.nodeName.toUpperCase() == ancestorTag) {
- if (!ancestorClass || ancestor.classList.contains(ancestorClass)) {
- return true;
- }
+ if (ancestor.nodeName.toUpperCase() == ancestorTag &&
+ (ancestorClass == null ||
+ ancestor.classList.contains(ancestorClass))) {
+ return true;
}
ancestor = ancestor.parentNode;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]