fix(web): emoji length computation (#1864)

This commit is contained in:
Mo
2022-10-23 11:04:17 -05:00
committed by GitHub
parent 1173a392c5
commit bda16b88c0
54 changed files with 826 additions and 21 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -30,7 +30,7 @@
"@babel/preset-env": "*", "@babel/preset-env": "*",
"@babel/preset-typescript": "^7.18.6", "@babel/preset-typescript": "^7.18.6",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@types/jest": "^29.0.2", "@types/jest": "^29.2.0",
"@types/react": "^18.0.20", "@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/styled-components": "^5.1.26", "@types/styled-components": "^5.1.26",
@@ -47,8 +47,8 @@
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"html-webpack-plugin": "^5.5.0", "html-webpack-plugin": "^5.5.0",
"identity-obj-proxy": "^3.0.0", "identity-obj-proxy": "^3.0.0",
"jest": "^28.1.2", "jest": "^29.2.1",
"jest-environment-jsdom": "^28.1.2", "jest-environment-jsdom": "^29.2.1",
"lint-staged": ">=12", "lint-staged": ">=12",
"mini-css-extract-plugin": "^2.6.1", "mini-css-extract-plugin": "^2.6.1",
"node-sass": "*", "node-sass": "*",
@@ -61,8 +61,8 @@
"sass-loader": "*", "sass-loader": "*",
"svg-jest": "^1.0.1", "svg-jest": "^1.0.1",
"tailwindcss": "^3.1.8", "tailwindcss": "^3.1.8",
"ts-jest": "^28.0.5", "ts-jest": "^29.0.3",
"ts-loader": "^9.3.1", "ts-loader": "^9.4.1",
"typescript": "*", "typescript": "*",
"webpack": "*", "webpack": "*",
"webpack-dev-server": "*", "webpack-dev-server": "*",

View File

@@ -255,8 +255,8 @@ const ContentListView: FunctionComponent<Props> = ({
return return
} }
for (const file of files) { for (let i = 0; i < files.length; i++) {
void filesController.uploadNewFile(file) void filesController.uploadNewFile(files[i])
} }
}} }}
/> />

View File

@@ -0,0 +1,13 @@
/**
* @jest-environment jsdom
*/
import { getEmojiLength } from './EmojiLength'
describe('emoji length', () => {
it('returns the correct length', () => {
expect(getEmojiLength('✍️')).toEqual(1)
expect(getEmojiLength('👩‍👩‍👧‍👦')).toEqual(1)
expect(getEmojiLength('👩‍❤️‍💋‍👩')).toEqual(1)
})
})

View File

@@ -0,0 +1,7 @@
export function getEmojiLength(emoji: string): number {
try {
return [...new Intl.Segmenter().segment(emoji)].length
} catch (error) {
return [...emoji].length
}
}

View File

@@ -2,6 +2,7 @@ import { EmojiString, Platform, VectorIconNameOrEmoji } from '@standardnotes/snj
import { FunctionComponent, useMemo, useRef, useState } from 'react' import { FunctionComponent, useMemo, useRef, useState } from 'react'
import Dropdown from '../Dropdown/Dropdown' import Dropdown from '../Dropdown/Dropdown'
import { DropdownItem } from '../Dropdown/DropdownItem' import { DropdownItem } from '../Dropdown/DropdownItem'
import { getEmojiLength } from './EmojiLength'
import { isIconEmoji } from './Icon' import { isIconEmoji } from './Icon'
import { IconNameToSvgMapping } from './IconNameToSvgMapping' import { IconNameToSvgMapping } from './IconNameToSvgMapping'
import { IconPickerType } from './IconPickerType' import { IconPickerType } from './IconPickerType'
@@ -72,7 +73,7 @@ const IconPicker = ({ selectedValue, onIconChange, platform, className }: Props)
const handleEmojiChange = (value: EmojiString) => { const handleEmojiChange = (value: EmojiString) => {
setEmojiInputValue(value) setEmojiInputValue(value)
const emojiLength = [...value].length const emojiLength = getEmojiLength(value)
if (emojiLength === 1) { if (emojiLength === 1) {
onIconChange(value) onIconChange(value)
emojiInputRef.current?.blur() emojiInputRef.current?.blur()

View File

@@ -898,8 +898,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
const observer = new MutationObserver((records) => { const observer = new MutationObserver((records) => {
for (const record of records) { for (const record of records) {
const removedNodes = record.removedNodes.values() record.removedNodes.forEach((node) => {
for (const node of removedNodes) {
if (node === editor) { if (node === editor) {
this.removeTabObserver?.() this.removeTabObserver?.()
this.removeTabObserver = undefined this.removeTabObserver = undefined
@@ -907,7 +906,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
editor.removeEventListener('scroll', this.resetScrollPosition) editor.removeEventListener('scroll', this.resetScrollPosition)
this.scrollPosition = 0 this.scrollPosition = 0
} }
} })
} }
}) })

View File

@@ -2,6 +2,7 @@
"extends": "../../node_modules/@standardnotes/config/src/tsconfig.json", "extends": "../../node_modules/@standardnotes/config/src/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"skipLibCheck": true, "skipLibCheck": true,
"lib": ["ES2022"],
"target": "ES2019", "target": "ES2019",
"module": "commonjs", "module": "commonjs",
"moduleResolution": "node", "moduleResolution": "node",

804
yarn.lock

File diff suppressed because it is too large Load Diff