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

Commit

Permalink
Remove gating on draft_non_native_insertion_forces_selection
Browse files Browse the repository at this point in the history
Summary: No bugs reported.

Reviewed By: stopachka

Differential Revision: D9273799

fbshipit-source-id: ee714cbf0d76baca6f121939082138b53118f106
  • Loading branch information
sophiebits authored and facebook-github-bot committed Aug 14, 2018
1 parent 05208a8 commit 1a5b27a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 52 deletions.
Expand Up @@ -81,7 +81,7 @@ Immutable.Record {
"focusKey": "a",
"focusOffset": 1,
"isBackward": false,
"hasFocus": true,
"hasFocus": false,
}
`;

Expand All @@ -91,7 +91,7 @@ Immutable.Record {
"anchorOffset": 1,
"focusKey": "a",
"focusOffset": 1,
"isBackward": true,
"hasFocus": true,
"isBackward": false,
"hasFocus": false,
}
`;
59 changes: 14 additions & 45 deletions src/component/handlers/edit/editOnBeforeInput.js
Expand Up @@ -20,7 +20,6 @@ const EditorState = require('EditorState');
const UserAgent = require('UserAgent');

const getEntityKeyForSelection = require('getEntityKeyForSelection');
const gkx = require('gkx');
const isEventHandled = require('isEventHandled');
const isSelectionAtLeafStart = require('isSelectionAtLeafStart');
const nullthrows = require('nullthrows');
Expand All @@ -37,10 +36,6 @@ const FF_QUICKFIND_CHAR = "'";
const FF_QUICKFIND_LINK_CHAR = '/';
const isFirefox = UserAgent.isBrowser('Firefox');

const nonNativeInsertionForcesSelection = gkx(
'draft_non_native_insertion_forces_selection',
);

function mustPreventDefaultForCharacter(character: string): boolean {
return (
isFirefox &&
Expand Down Expand Up @@ -122,46 +117,22 @@ function editOnBeforeInput(
// is not collapsed, we will re-render.
const selection = editorState.getSelection();
const selectionStart = selection.getStartOffset();
const selectionEnd = selection.getEndOffset();
const anchorKey = selection.getAnchorKey();

if (!selection.isCollapsed()) {
e.preventDefault();

// If the currently selected text matches what the user is trying to
// replace it with, let's just update the `SelectionState`. If not, update
// the `ContentState` with the new text.
const currentlySelectedChars = editorState
.getCurrentContent()
.getPlainText()
.slice(selectionStart, selectionEnd);
if (
!nonNativeInsertionForcesSelection &&
chars === currentlySelectedChars
) {
editor.update(
EditorState.forceSelection(
editorState,
selection.merge({
anchorOffset: selectionEnd,
focusOffset: selectionEnd,
}),
),
);
} else {
editor.update(
replaceText(
editorState,
chars,
editorState.getCurrentInlineStyle(),
getEntityKeyForSelection(
editorState.getCurrentContent(),
editorState.getSelection(),
),
true,
editor.update(
replaceText(
editorState,
chars,
editorState.getCurrentInlineStyle(),
getEntityKeyForSelection(
editorState.getCurrentContent(),
editorState.getSelection(),
),
);
}
true,
),
);
return;
}

Expand Down Expand Up @@ -270,11 +241,9 @@ function editOnBeforeInput(

if (mustPreventNative) {
e.preventDefault();
if (nonNativeInsertionForcesSelection) {
newEditorState = EditorState.set(newEditorState, {
forceSelection: true,
});
}
newEditorState = EditorState.set(newEditorState, {
forceSelection: true,
});
editor.update(newEditorState);
return;
}
Expand Down
4 changes: 0 additions & 4 deletions src/model/immutable/EditorState.js
Expand Up @@ -24,7 +24,6 @@ const ContentState = require('ContentState');
const EditorBidiService = require('EditorBidiService');
const SelectionState = require('SelectionState');

const gkx = require('gkx');
const Immutable = require('immutable');

const {OrderedSet, Record, Stack} = Immutable;
Expand Down Expand Up @@ -348,9 +347,6 @@ class EditorState {
return editorState;
}

if (!gkx('draft_non_native_insertion_forces_selection')) {
forceSelection = changeType !== 'insert-characters';
}
const directionMap = EditorBidiService.getDirectionMap(
contentState,
editorState.getDirectionMap(),
Expand Down

0 comments on commit 1a5b27a

Please sign in to comment.