From 855e25f8da2d5dfd16a50aaf08405c3b8e6634ef Mon Sep 17 00:00:00 2001 From: song Date: Wed, 18 Nov 2020 23:44:37 -0700 Subject: [PATCH] UnhangRange considers void nodes - Include void node in range - Add delete-void-at-end test - Add delete-void-and-newline-at-end test --- .DS_Store | Bin 0 -> 6148 bytes packages/slate/src/interfaces/editor.ts | 9 +++- .../delete-void-and-newline-at-end.tsx | 40 ++++++++++++++++++ .../delete/voids-true/delete-void-at-end.tsx | 34 +++++++++++++++ site/.DS_Store | Bin 0 -> 6148 bytes 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 packages/slate/test/transforms/delete/voids-true/delete-void-and-newline-at-end.tsx create mode 100644 packages/slate/test/transforms/delete/voids-true/delete-void-at-end.tsx create mode 100644 site/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..03dcbfd4e851303c96fbd9d9f02ddde73bfefe0a GIT binary patch literal 6148 zcmeHK&2G~`5T0#A>x5Jd5>hz&g2W+;(t;=zLW2ISL_A{tP$U~M`K1BQWrjRD@fRXU&(awx>Uz1+Ve@{Wd4-yKFSZ1@B5 z5arGEsE@rK(pw5>khA@kv)x7vwoPaPYnP_b0vWMMg-D{F^DdDG?>@!ZDB?@b zu7arqiL)y>E`Q^qXn1i%^nV#Y84)PeSWYwM+J8=IC@u_{}YH{FwH)=ivb8h4z@D{eh? zk`q_!&!cE~p*!x2z@PPMHxHsPae~mFNaw)wVe_RgcD)@V?Ki>C6tghK>X=ZHWr^2!hNUeq8K-yCpJqDaS*BCW8?X4LJbAHJaJ}L@OR8cVQgz$D&#KimsbE_iQ6pD`B#C_*4Wm#REQ@K zpf Editor.isBlock(editor, n), }) + + // If last element is a void node, unhang range by including void node in range + if (Editor.isVoid(editor, endBlock[0])) { + end = { path: end.path, offset: 1 } + return { anchor: start, focus: end } + } + const blockPath = endBlock ? endBlock[1] : [] const first = Editor.start(editor, []) const before = { anchor: first, focus: end } @@ -1274,7 +1281,7 @@ export const Editor = { at: before, match: Text.isText, reverse: true, - voids, + voids: true, })) { if (skip) { skip = false diff --git a/packages/slate/test/transforms/delete/voids-true/delete-void-and-newline-at-end.tsx b/packages/slate/test/transforms/delete/voids-true/delete-void-and-newline-at-end.tsx new file mode 100644 index 0000000000..980a82bfcb --- /dev/null +++ b/packages/slate/test/transforms/delete/voids-true/delete-void-and-newline-at-end.tsx @@ -0,0 +1,40 @@ +/** @jsx jsx */ +import { Editor, Transforms } from 'slate' +import { jsx } from '../../..' + +export const input = ( + + + + + This is a first paragraph + + + + This is the second paragraph + + + + + + + + + + +) +export const run = editor => { + editor.deleteFragment(editor) +} +export const output = ( + + + + + + + + + + +) diff --git a/packages/slate/test/transforms/delete/voids-true/delete-void-at-end.tsx b/packages/slate/test/transforms/delete/voids-true/delete-void-at-end.tsx new file mode 100644 index 0000000000..7243586805 --- /dev/null +++ b/packages/slate/test/transforms/delete/voids-true/delete-void-at-end.tsx @@ -0,0 +1,34 @@ +/** @jsx jsx */ +import { Editor, Transforms } from 'slate' +import { jsx } from '../../..' + +export const input = ( + + + + + This is a first paragraph + + + + This is the second paragraph + + + + + + + +) +export const run = editor => { + editor.deleteFragment(editor) +} +export const output = ( + + + + + + + +) diff --git a/site/.DS_Store b/site/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f4ddc634d202c9ca29513438f033a6ec78d28cd3 GIT binary patch literal 6148 zcmeHK(QeZ)6un-%krq1oFsVG|1&N1JbpvfoXi`==2bXcU<17tEIWy%D{pfR4d^ zv&8*a;Fgftgp$Gx-wIKyP{6~8%UN*N=b5ZCk^VFu8GXL^qcDh*cKfSXDV0~(t~pNC zsn)8mdM9$)OT1(fcfIioetP01C%&mal`_1jd;YUvI6bUyJd#o31<`P<$iZNUkeAPc zXdtIuIf(|b8mFf_9H-(`4(pBieCt8e-P+w&sKKR;7|C3N+!dz-Z%$l zs;1TuuddwJ%FlV_)YqO>4nkhKnfLEpzx0{x1Xcm7!2hNI?+-4Vv12gRsJ0Fi>IwiX zqgfg1{5OF)uECDMR3my|LQ{d7D$Er_Xgb%0ww)e=kx#ZpYQ*9l6|rYSOu<>0;0U%+wUSJbG9xe$7ihzKZ3JyT&ht~ kP?+ObRrn~r1y_bXmn*=I!Bit!VD^uIlED^MfxoK25BZS-3jhEB literal 0 HcmV?d00001