1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var DraftModifier = require("./DraftModifier");
|
14 |
|
15 | var gkx = require("./gkx");
|
16 |
|
17 | var experimentalTreeDataSupport = gkx('draft_tree_data_support');
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function removeTextWithStrategy(editorState, strategy, direction) {
|
24 | var selection = editorState.getSelection();
|
25 | var content = editorState.getCurrentContent();
|
26 | var target = selection;
|
27 | var anchorKey = selection.getAnchorKey();
|
28 | var focusKey = selection.getFocusKey();
|
29 | var anchorBlock = content.getBlockForKey(anchorKey);
|
30 |
|
31 | if (experimentalTreeDataSupport) {
|
32 | if (direction === 'forward') {
|
33 | if (anchorKey !== focusKey) {
|
34 |
|
35 |
|
36 | return content;
|
37 | }
|
38 | }
|
39 | }
|
40 |
|
41 | if (selection.isCollapsed()) {
|
42 | if (direction === 'forward') {
|
43 | if (editorState.isSelectionAtEndOfContent()) {
|
44 | return content;
|
45 | }
|
46 |
|
47 | if (experimentalTreeDataSupport) {
|
48 | var isAtEndOfBlock = selection.getAnchorOffset() === content.getBlockForKey(anchorKey).getLength();
|
49 |
|
50 | if (isAtEndOfBlock) {
|
51 | var anchorBlockSibling = content.getBlockForKey(anchorBlock.nextSibling);
|
52 |
|
53 | if (!anchorBlockSibling || anchorBlockSibling.getLength() === 0) {
|
54 |
|
55 |
|
56 | return content;
|
57 | }
|
58 | }
|
59 | }
|
60 | } else if (editorState.isSelectionAtStartOfContent()) {
|
61 | return content;
|
62 | }
|
63 |
|
64 | target = strategy(editorState);
|
65 |
|
66 | if (target === selection) {
|
67 | return content;
|
68 | }
|
69 | }
|
70 |
|
71 | return DraftModifier.removeRange(content, target, direction);
|
72 | }
|
73 |
|
74 | module.exports = removeTextWithStrategy; |
\ | No newline at end of file |