Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit b2f6ed0

Browse files
sophiebitsfacebook-github-bot
authored andcommitted
Remove old decorator fingerprint logic
Reviewed By: mitermayer Differential Revision: D7977136 fbshipit-source-id: e6389c58d668b8c403020bfa3f740c4f777add75
1 parent 3798902 commit b2f6ed0

File tree

5 files changed

+54
-101
lines changed

5 files changed

+54
-101
lines changed

src/component/handlers/edit/__tests__/editOnBeforeInput.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
'use strict';
1515

1616
jest.disableAutomock();
17-
jest.mock('gkx', () => name => name === 'draft_improved_decorator_fingerprint');
1817

1918
const CompositeDraftDecorator = require('CompositeDraftDecorator');
2019
const ContentBlock = require('ContentBlock');

src/component/handlers/edit/editOnBeforeInput.js

Lines changed: 54 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
import type DraftEditor from 'DraftEditor.react';
1616
import type {DraftInlineStyle} from 'DraftInlineStyle';
1717

18-
const BlockTree = require('BlockTree');
1918
const DraftModifier = require('DraftModifier');
2019
const EditorState = require('EditorState');
2120
const UserAgent = require('UserAgent');
2221

2322
const getEntityKeyForSelection = require('getEntityKeyForSelection');
24-
const gkx = require('gkx');
2523
const isEventHandled = require('isEventHandled');
2624
const isSelectionAtLeafStart = require('isSelectionAtLeafStart');
2725
const nullthrows = require('nullthrows');
@@ -190,73 +188,60 @@ function editOnBeforeInput(
190188
}
191189
}
192190
if (!mustPreventNative) {
193-
if (gkx('draft_improved_decorator_fingerprint')) {
194-
// Let's say we have a decorator that highlights hashtags. In many cases
195-
// we need to prevent native behavior and rerender ourselves --
196-
// particularly, any case *except* where the inserted characters end up
197-
// anywhere except exactly where you put them.
198-
//
199-
// Using [] to denote a decorated leaf, some examples:
200-
//
201-
// 1. 'hi #' and append 'f'
202-
// desired rendering: 'hi [#f]'
203-
// native rendering would be: 'hi #f' (incorrect)
204-
//
205-
// 2. 'x [#foo]' and insert '#' before 'f'
206-
// desired rendering: 'x #[#foo]'
207-
// native rendering would be: 'x [##foo]' (incorrect)
208-
//
209-
// 3. '[#foobar]' and insert ' ' between 'foo' and 'bar'
210-
// desired rendering: '[#foo] bar'
211-
// native rendering would be: '[#foo bar]' (incorrect)
212-
//
213-
// 4. '[#foo]' and delete '#' [won't use this beforeinput codepath though]
214-
// desired rendering: 'foo'
215-
// native rendering would be: '[foo]' (incorrect)
216-
//
217-
// 5. '[#foo]' and append 'b'
218-
// desired rendering: '[#foob]'
219-
// native rendering would be: '[#foob]' (native insertion is OK here)
220-
//
221-
// It is safe to allow native insertion if and only if the full list of
222-
// decorator ranges matches what we expect native insertion to give. We
223-
// don't need to compare the content because the only possible mutation
224-
// to consider here is inserting plain text and decorators can't affect
225-
// text content.
226-
const oldBlockTree = editorState.getBlockTree(anchorKey);
227-
const newBlockTree = newEditorState.getBlockTree(anchorKey);
228-
mustPreventNative =
229-
oldBlockTree.size !== newBlockTree.size ||
230-
oldBlockTree.zip(newBlockTree).some(([oldLeafSet, newLeafSet]) => {
231-
// selectionStart is guaranteed to be selectionEnd here
232-
const oldStart = oldLeafSet.get('start');
233-
const adjustedStart =
234-
oldStart + (oldStart >= selectionStart ? chars.length : 0);
235-
const oldEnd = oldLeafSet.get('end');
236-
const adjustedEnd =
237-
oldEnd + (oldEnd >= selectionStart ? chars.length : 0);
238-
return (
239-
// Different decorators
240-
oldLeafSet.get('decoratorKey') !== newLeafSet.get('decoratorKey') ||
241-
// Different number of inline styles
242-
oldLeafSet.get('leaves').size !== newLeafSet.get('leaves').size ||
243-
// Different effective decorator position
244-
adjustedStart !== newLeafSet.get('start') ||
245-
adjustedEnd !== newLeafSet.get('end')
246-
);
247-
});
248-
} else {
249-
// Check the old and new "fingerprints" of the current block to determine
250-
// whether this insertion requires any addition or removal of text nodes,
251-
// in which case we would prevent the native character insertion.
252-
const originalFingerprint = BlockTree.getFingerprint(
253-
editorState.getBlockTree(anchorKey),
254-
);
255-
const newFingerprint = BlockTree.getFingerprint(
256-
newEditorState.getBlockTree(anchorKey),
257-
);
258-
mustPreventNative = originalFingerprint !== newFingerprint;
259-
}
191+
// Let's say we have a decorator that highlights hashtags. In many cases
192+
// we need to prevent native behavior and rerender ourselves --
193+
// particularly, any case *except* where the inserted characters end up
194+
// anywhere except exactly where you put them.
195+
//
196+
// Using [] to denote a decorated leaf, some examples:
197+
//
198+
// 1. 'hi #' and append 'f'
199+
// desired rendering: 'hi [#f]'
200+
// native rendering would be: 'hi #f' (incorrect)
201+
//
202+
// 2. 'x [#foo]' and insert '#' before 'f'
203+
// desired rendering: 'x #[#foo]'
204+
// native rendering would be: 'x [##foo]' (incorrect)
205+
//
206+
// 3. '[#foobar]' and insert ' ' between 'foo' and 'bar'
207+
// desired rendering: '[#foo] bar'
208+
// native rendering would be: '[#foo bar]' (incorrect)
209+
//
210+
// 4. '[#foo]' and delete '#' [won't use this beforeinput codepath though]
211+
// desired rendering: 'foo'
212+
// native rendering would be: '[foo]' (incorrect)
213+
//
214+
// 5. '[#foo]' and append 'b'
215+
// desired rendering: '[#foob]'
216+
// native rendering would be: '[#foob]' (native insertion is OK here)
217+
//
218+
// It is safe to allow native insertion if and only if the full list of
219+
// decorator ranges matches what we expect native insertion to give. We
220+
// don't need to compare the content because the only possible mutation
221+
// to consider here is inserting plain text and decorators can't affect
222+
// text content.
223+
const oldBlockTree = editorState.getBlockTree(anchorKey);
224+
const newBlockTree = newEditorState.getBlockTree(anchorKey);
225+
mustPreventNative =
226+
oldBlockTree.size !== newBlockTree.size ||
227+
oldBlockTree.zip(newBlockTree).some(([oldLeafSet, newLeafSet]) => {
228+
// selectionStart is guaranteed to be selectionEnd here
229+
const oldStart = oldLeafSet.get('start');
230+
const adjustedStart =
231+
oldStart + (oldStart >= selectionStart ? chars.length : 0);
232+
const oldEnd = oldLeafSet.get('end');
233+
const adjustedEnd =
234+
oldEnd + (oldEnd >= selectionStart ? chars.length : 0);
235+
return (
236+
// Different decorators
237+
oldLeafSet.get('decoratorKey') !== newLeafSet.get('decoratorKey') ||
238+
// Different number of inline styles
239+
oldLeafSet.get('leaves').size !== newLeafSet.get('leaves').size ||
240+
// Different effective decorator position
241+
adjustedStart !== newLeafSet.get('start') ||
242+
adjustedEnd !== newLeafSet.get('end')
243+
);
244+
});
260245
}
261246
if (!mustPreventNative) {
262247
mustPreventNative = mustPreventDefaultForCharacter(chars);

src/model/immutable/BlockTree.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,6 @@ const BlockTree = {
9393

9494
return List(leafSets);
9595
},
96-
97-
/**
98-
* Create a string representation of the given tree map. This allows us
99-
* to rapidly determine whether a tree has undergone a significant
100-
* structural change.
101-
*/
102-
getFingerprint: function(tree: List<DecoratorRange>): string {
103-
return tree
104-
.map(leafSet => {
105-
const decoratorKey = leafSet.get('decoratorKey');
106-
const fingerprintString =
107-
decoratorKey !== null
108-
? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start'))
109-
: '';
110-
return '' + fingerprintString + '.' + leafSet.get('leaves').size;
111-
})
112-
.join(FINGERPRINT_DELIMITER);
113-
},
11496
};
11597

11698
/**

src/model/immutable/__tests__/BlockTree-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ const assertBlockTreeGenerate = (
9797
const tree = BlockTree.generate(content, block, decorator);
9898

9999
expect(tree.toJS()).toMatchSnapshot();
100-
expect(BlockTree.getFingerprint(tree)).toMatchSnapshot();
101100

102101
// to remove
103102
return tree;

src/model/immutable/__tests__/__snapshots__/BlockTree-test.js.snap

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ Array [
2424
]
2525
`;
2626

27-
exports[`must generate for styled block with empty decorator 2`] = `".3"`;
28-
2927
exports[`must generate for styled block with multiple decorators 1`] = `
3028
Array [
3129
Object {
@@ -72,8 +70,6 @@ Array [
7270
]
7371
`;
7472

75-
exports[`must generate for styled block with multiple decorators 2`] = `"y.3.1-.2-z.4.2"`;
76-
7773
exports[`must generate for styled block with single decorator 1`] = `
7874
Array [
7975
Object {
@@ -120,8 +116,6 @@ Array [
120116
]
121117
`;
122118

123-
exports[`must generate for styled block with single decorator 2`] = `".1-x.3.2-.2"`;
124-
125119
exports[`must generate for unstyled block with empty decorator 1`] = `
126120
Array [
127121
Object {
@@ -138,8 +132,6 @@ Array [
138132
]
139133
`;
140134

141-
exports[`must generate for unstyled block with empty decorator 2`] = `".1"`;
142-
143135
exports[`must generate for unstyled block with multiple decorators 1`] = `
144136
Array [
145137
Object {
@@ -178,8 +170,6 @@ Array [
178170
]
179171
`;
180172

181-
exports[`must generate for unstyled block with multiple decorators 2`] = `"y.3.1-.1-z.1.1"`;
182-
183173
exports[`must generate for unstyled block with single decorator 1`] = `
184174
Array [
185175
Object {
@@ -217,5 +207,3 @@ Array [
217207
},
218208
]
219209
`;
220-
221-
exports[`must generate for unstyled block with single decorator 2`] = `".1-x.3.1-.1"`;

0 commit comments

Comments
 (0)