From 6dd4e846b705b3df2a7d2eb41aff2a0f1098000c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 11 Nov 2025 19:35:57 -0500 Subject: [PATCH] fix: Avoid seeing lang unneccessarily (#10623) --- app/models/Document.ts | 2 +- app/scenes/Document/components/Editor.tsx | 3 +- app/utils/language.ts | 43 +++++++++++++++++++ server/models/Document.ts | 2 +- server/queues/tasks/DocumentUpdateTextTask.ts | 4 +- shared/editor/components/Styles.ts | 16 ++++++- 6 files changed, 65 insertions(+), 5 deletions(-) diff --git a/app/models/Document.ts b/app/models/Document.ts index 5ecc852aa5..1ce0cfeb6b 100644 --- a/app/models/Document.ts +++ b/app/models/Document.ts @@ -134,7 +134,7 @@ export default class Document extends ArchivableModel implements Searchable { @observable title: string; - /** The likely language of the document. */ + /** The likely language of the document, in ISO 639-1 format. */ language: string | undefined; /** diff --git a/app/scenes/Document/components/Editor.tsx b/app/scenes/Document/components/Editor.tsx index 0783536908..31507c9f1f 100644 --- a/app/scenes/Document/components/Editor.tsx +++ b/app/scenes/Document/components/Editor.tsx @@ -33,6 +33,7 @@ import MultiplayerEditor from "./AsyncMultiplayerEditor"; import DocumentMeta from "./DocumentMeta"; import DocumentTitle from "./DocumentTitle"; import first from "lodash/first"; +import { getLangFor } from "~/utils/language"; const extensions = withUIExtensions(withComments(richExtensions)); @@ -229,7 +230,7 @@ function DocumentEditor(props: Props, ref: React.RefObject) { )} { const node = Node.fromJSON(schema, document.content); document.text = serializer.serialize(node); - const language = franc(DocumentHelper.toPlainText(document)); + const language = franc(DocumentHelper.toPlainText(document), { + minLength: 50, + }); document.language = iso6393To1[language]; await document.save({ silent: true }); diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index caba098fab..380a416e28 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -304,6 +304,12 @@ const emailStyle = (props: Props) => css` } `; +/** + * Adjustments to line-height and paragraph margins for complex scripts. If adding + * scripts here you also need to update the `getLangFor` method. + * + * @returns The CSS styles for complex scripts. + */ const textStyle = () => css` /* Southeast Asian scripts */ :lang(th), /* Thai */ @@ -312,7 +318,9 @@ const textStyle = () => css` :lang(my) { /* Burmese */ p { - line-height: 1.8; + line-height: 1.7; + margin-top: 0.8em; + margin-bottom: 0.8em; } } @@ -330,6 +338,8 @@ const textStyle = () => css` /* Sinhala */ p { line-height: 1.7; + margin-top: 0.8em; + margin-bottom: 0.8em; } } @@ -337,6 +347,8 @@ const textStyle = () => css` :lang(bo) { p { line-height: 1.8; + margin-top: 0.8em; + margin-bottom: 0.8em; } } @@ -357,6 +369,8 @@ const textStyle = () => css` /* Mongolian */ p { line-height: 1.7; + margin-top: 0.8em; + margin-bottom: 0.8em; } } `;