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

Add unicode sequences support #4326

Merged
merged 17 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions .changeset/lucky-schools-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': minor
---

Add support for [flag](https://emojipedia.org/emoji-flag-sequence/), [keycap](https://emojipedia.org/emoji-keycap-sequence/) and [tag](https://emojipedia.org/emoji-tag-sequence/) unicode sequences.
1 change: 0 additions & 1 deletion config/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function configure(pkg, env, target) {
// we have to manually specify named exports here for them to work.
// https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports
namedExports: {
esrever: ['reverse'],
'react-dom': ['findDOMNode'],
'react-dom/server': ['renderToStaticMarkup'],
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"internal:release:next": "yarn prerelease && yarn changeset publish --tag next",
"serve": "cd ./site && next",
"start": "npm-run-all --parallel --print-label watch serve",
"test": "mocha --require ./config/babel/register.cjs ./packages/*/test/index.js",
"test": "mocha --require ./config/babel/register.cjs ./packages/*/test/**/*.{js,ts}",
dylans marked this conversation as resolved.
Show resolved Hide resolved
"test:custom": "mocha --require ./config/babel/register.cjs ./packages/slate/test/index.js",
"test:inspect": "yarn test --inspect-brk",
"test:integration": "run-p -r serve cypress:run",
Expand Down
2 changes: 0 additions & 2 deletions packages/slate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"dist/"
],
"dependencies": {
"@types/esrever": "^0.2.0",
"esrever": "^0.2.0",
"fast-deep-equal": "^3.1.3",
"immer": "^8.0.1",
"is-plain-object": "^3.0.0",
Expand Down
14 changes: 6 additions & 8 deletions packages/slate/src/interfaces/editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isPlainObject from 'is-plain-object'
import { reverse as reverseText } from 'esrever'

import {
Ancestor,
Expand All @@ -25,7 +24,7 @@ import {
POINT_REFS,
RANGE_REFS,
} from '../utils/weak-maps'
import { getWordDistance, getCharacterDistance } from '../utils/string'
import { getWordDistance, getCharacterDistance, split } from '../utils/string'
import { Descendant } from './node'
import { Element } from './element'

Expand Down Expand Up @@ -1338,7 +1337,6 @@ export const Editor: EditorInterface = {
: Editor.start(editor, path)

blockText = Editor.string(editor, { anchor: s, focus: e }, { voids })
blockText = reverse ? reverseText(blockText) : blockText
isNewBlock = true
}
}
Expand Down Expand Up @@ -1379,8 +1377,8 @@ export const Editor: EditorInterface = {
// otherwise advance blockText forward by the new `distance`.
if (distance === 0) {
if (blockText === '') break
distance = calcDistance(blockText, unit)
blockText = blockText.slice(distance)
distance = calcDistance(blockText, unit, reverse)
blockText = split(blockText, distance, reverse)[1]
oliger marked this conversation as resolved.
Show resolved Hide resolved
}

// Advance `leafText` by the current `distance`.
Expand Down Expand Up @@ -1411,11 +1409,11 @@ export const Editor: EditorInterface = {

// Helper:
// Return the distance in offsets for a step of size `unit` on given string.
function calcDistance(text: string, unit: string) {
function calcDistance(text: string, unit: string, reverse: boolean) {
oliger marked this conversation as resolved.
Show resolved Hide resolved
if (unit === 'character') {
return getCharacterDistance(text)
return getCharacterDistance(text, reverse)
} else if (unit === 'word') {
return getWordDistance(text)
return getWordDistance(text, reverse)
} else if (unit === 'line' || unit === 'block') {
return text.length
}
Expand Down
Loading