Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail body text color in reply #7875

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/common/gui/main-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ styles.registerStyle("main", () => {
".bg-white": {
"background-color": "white",
},
".bg-fix-quoted blockquote.tutanota_quote": {
"background-color": "white",
color: "black",
// make the border thicker so it is easier to see
"border-width": "4px",
},
".content-black": {
color: "black",
},
Expand Down
10 changes: 9 additions & 1 deletion src/mail-app/mail/editor/MailEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
import { FileOpenError } from "../../../common/api/common/error/FileOpenError"
import type { lazy } from "@tutao/tutanota-utils"
import { assertNotNull, cleanMatch, downcast, isNotNull, noOp, ofClass, typedValues } from "@tutao/tutanota-utils"
import { createInlineImage, replaceCidsWithInlineImages, replaceInlineImagesWithCids } from "../view/MailGuiUtils"
import { createInlineImage, isMailContrastFixNeeded, replaceCidsWithInlineImages, replaceInlineImagesWithCids } from "../view/MailGuiUtils"
import { client } from "../../../common/misc/ClientDetector"
import { appendEmailSignature } from "../signature/Signature"
import { showTemplatePopupInEditor } from "../../templates/view/TemplatePopup"
Expand Down Expand Up @@ -195,6 +195,14 @@ export class MailEditor implements Component<MailEditorAttrs> {
this.editor.initialized.promise.then(() => {
this.editor.setHTML(model.getBody())

const editorDom = this.editor.getDOM()
const contrastFixNeeded = isMailContrastFixNeeded(editorDom)
// If mail body cannot be displayed as-is on the dark background then apply the background and text color
// fix. This class will change tutanota-quote's inside of it.
if (contrastFixNeeded) {
editorDom.classList.add("bg-fix-quoted")
}

this.processInlineImages()

// Add mutation observer to remove attachments when corresponding DOM element is removed
Expand Down
8 changes: 8 additions & 0 deletions src/mail-app/mail/view/MailGuiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,11 @@ export function getConfidentialFontIcon(mail: Mail): String {
const confidentialIcon = getConfidentialIcon(mail)
return confidentialIcon === Icons.PQLock ? FontIcons.PQConfidential : FontIcons.Confidential
}

export function isMailContrastFixNeeded(editorDom: ParentNode): boolean {
return (
Array.from(editorDom.querySelectorAll("*[style]"), (e) => (e as HTMLElement).style).some(
(s) => (s.color && s.color !== "inherit") || (s.backgroundColor && s.backgroundColor !== "inherit"),
) || editorDom.querySelectorAll("font[color]").length > 0
)
}
7 changes: 2 additions & 5 deletions src/mail-app/mail/view/MailViewerViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { LoginController } from "../../../common/api/main/LoginController"
import m from "mithril"
import { LockedError, NotAuthorizedError, NotFoundError } from "../../../common/api/common/error/RestError"
import { haveSameId, isSameId } from "../../../common/api/common/utils/EntityUtils"
import { getReferencedAttachments, isTutanotaTeamMail, loadInlineImages, moveMails } from "./MailGuiUtils"
import { getReferencedAttachments, isMailContrastFixNeeded, isTutanotaTeamMail, loadInlineImages, moveMails } from "./MailGuiUtils"
import { SanitizedFragment } from "../../../common/misc/HtmlSanitizer"
import { CALENDAR_MIME_TYPE, FileController } from "../../../common/file/FileController"
import { exportMails } from "../export/Exporter.js"
Expand Down Expand Up @@ -967,10 +967,7 @@ export class MailViewerViewModel {
* * any tag with a style attribute that has the background-color set (besides "inherit")
* * any font tag with the color attribute set
*/
this.contrastFixNeeded =
Array.from(fragment.querySelectorAll("*[style]"), (e) => (e as HTMLElement).style).some(
(s) => (s.color && s.color !== "inherit") || (s.backgroundColor && s.backgroundColor !== "inherit"),
) || fragment.querySelectorAll("font[color]").length > 0
this.contrastFixNeeded = isMailContrastFixNeeded(fragment)

m.redraw()
return {
Expand Down