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

RTL fixes in the chat #2300 #2383

Merged
merged 3 commits into from
Dec 13, 2023
Merged
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
35 changes: 24 additions & 11 deletions src/shared/utils/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BaseProposal } from "@/shared/models/governance/proposals";
import { transformFirebaseDataList } from "@/shared/utils/transformFirebaseDataToModel";
import { BASE_URL } from "../constants";
import { Common, DateFormat, Time, User } from "../models";
import { ElementType } from "../ui-kit/TextEditor/constants";

export const getPrefix = (currency: Currency): string => {
switch (currency) {
Expand Down Expand Up @@ -201,22 +202,34 @@ export const isRTL = (text = ""): boolean => {
};

export const isRtlText = (text = ""): boolean => {
for (let i = 0; i < text.length; i++) {
const charCode = text.charCodeAt(i);
try {
const parsedText = JSON.parse(text);
const textWithNoMentions = JSON.stringify(
parsedText[0].children?.filter(
(item) => item.type !== ElementType.Mention,
),
);

for (let i = 0; i < textWithNoMentions.length; i++) {
const charCode = textWithNoMentions.charCodeAt(i);

// Hebrew Block
if (charCode >= 0x0590 && charCode <= 0x05ff) return true;
// Hebrew Block
if (charCode >= 0x0590 && charCode <= 0x05ff) return true;

// Arabic Block
if (charCode >= 0x0600 && charCode <= 0x06ff) return true;
// Arabic Block
if (charCode >= 0x0600 && charCode <= 0x06ff) return true;

// Arabic Supplement Block
if (charCode >= 0x0750 && charCode <= 0x077f) return true;
// Arabic Supplement Block
if (charCode >= 0x0750 && charCode <= 0x077f) return true;

// Arabic Extended-A Block
if (charCode >= 0x08a0 && charCode <= 0x08ff) return true;
// Arabic Extended-A Block
if (charCode >= 0x08a0 && charCode <= 0x08ff) return true;
}
return false;
} catch (error) {
console.error(error);
return false;
}
return false;
};

/**
Expand Down
Loading