-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix overly-aggressive unhangRange (#5193)
`Editor.unhangRange()` could decide to proceed with an adjustment in cases where the range was not hanging. Because the algorithm it uses *always* skips over the first node it encounters, this meant the selection was adjusted in non-hanging cases. This change reduces the chances of an incorrect decision to adjust. Transforms now pass the `voids` flag to `unhangRange()` as it seems logical that the adjusted range should reflect the intention of the operation. This fixes a unit test I added for markable voids that had to be skipped because of the `unhangRange()` error, and fixes a couple other long-skipped tests.
- Loading branch information
1 parent
c8c75e9
commit 6909a8f
Showing
13 changed files
with
183 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate': patch | ||
--- | ||
|
||
Stops Editor.unhangRange() from adjusting the range in some cases when it was not actually hanging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...est/interfaces/Editor/unhangRange/block-hanging-over-non-empty-void-with-voids-option.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** @jsx jsx */ | ||
import { Editor } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<anchor /> | ||
This is a first paragraph | ||
</block> | ||
<block>This is the second paragraph</block> | ||
<block void> | ||
This is the third paragraph | ||
{/* unhang should move focus to here */} | ||
</block> | ||
<block> | ||
<focus /> | ||
</block> | ||
</editor> | ||
) | ||
|
||
export const test = editor => { | ||
return Editor.unhangRange(editor, editor.selection, { voids: true }) | ||
} | ||
|
||
export const output = { | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [2, 0], offset: 27 }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/slate/test/interfaces/Editor/unhangRange/inline-at-end.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** @jsx jsx */ | ||
import { Editor } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<anchor /> | ||
This is a first paragraph | ||
<inline void> | ||
<text /> | ||
</inline> | ||
<text /> | ||
{/* unhang should move focus to here */} | ||
</block> | ||
<block> | ||
<focus /> | ||
This is the second paragraph | ||
</block> | ||
</editor> | ||
) | ||
|
||
export const test = editor => { | ||
return Editor.unhangRange(editor, editor.selection, { voids: true }) | ||
} | ||
|
||
export const output = { | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [0, 2], offset: 0 }, | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/slate/test/interfaces/Editor/unhangRange/multi-block-inline-at-end.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** @jsx jsx */ | ||
import { Editor } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<anchor /> | ||
This is the first paragraph | ||
<inline void> | ||
<text /> | ||
</inline> | ||
<text /> | ||
</block> | ||
<block> | ||
This is the second paragraph | ||
<inline void> | ||
<text /> | ||
</inline> | ||
<text /> | ||
{/* unhang should move focus to here */} | ||
</block> | ||
<block> | ||
<focus /> | ||
This is the third paragraph | ||
</block> | ||
</editor> | ||
) | ||
|
||
export const test = editor => { | ||
return Editor.unhangRange(editor, editor.selection, { voids: true }) | ||
} | ||
|
||
export const output = { | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [1, 2], offset: 0 }, | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/slate/test/interfaces/Editor/unhangRange/not-hanging-inline-at-end.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** @jsx jsx */ | ||
/* The starting selection range is not hanging, so should not be adjusted */ | ||
import { Editor } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<anchor /> | ||
This is the first paragraph | ||
<inline void> | ||
<text /> | ||
</inline> | ||
<text> | ||
<focus /> | ||
</text> | ||
</block> | ||
<block>This is the second paragraph</block> | ||
</editor> | ||
) | ||
|
||
export const test = editor => { | ||
return Editor.unhangRange(editor, editor.selection, { voids: true }) | ||
} | ||
|
||
export const output = { | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [0, 2], offset: 0 }, | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/slate/test/interfaces/Editor/unhangRange/not-hanging-multi-block-inline-at-end.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** @jsx jsx */ | ||
/* The starting selection range is not hanging, so should not be adjusted */ | ||
import { Editor } from 'slate' | ||
import { jsx } from '../../..' | ||
|
||
export const input = ( | ||
<editor> | ||
<block> | ||
<anchor /> | ||
This is the first paragraph | ||
<inline void> | ||
<text /> | ||
</inline> | ||
<text /> | ||
</block> | ||
<block> | ||
This is the second paragraph | ||
<inline void> | ||
<text /> | ||
</inline> | ||
<text> | ||
<focus /> | ||
</text> | ||
</block> | ||
<block>This is the third paragraph</block> | ||
</editor> | ||
) | ||
|
||
export const test = editor => { | ||
return Editor.unhangRange(editor, editor.selection, { voids: true }) | ||
} | ||
|
||
export const output = { | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [1, 2], offset: 0 }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,3 @@ export const output = ( | |
</block> | ||
</editor> | ||
) | ||
export const skip = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,3 @@ export const output = ( | |
<block>two</block> | ||
</editor> | ||
) | ||
export const skip = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters