Skip to content

Commit

Permalink
Fix scroll behavior when node has tab chars (facebookarchive#2256)
Browse files Browse the repository at this point in the history
Summary:
Closes facebookarchive#2254

Problem behavior and reasoning behind solution is described in the issue.

The linter issues are unrelated to the file I changed so I left them alone in order to keep this commit atomic.
Pull Request resolved: facebookarchive#2256

Reviewed By: claudiopro

Differential Revision: D18734244

Pulled By: mrkev

fbshipit-source-id: eb5a1a91f7c3f27fced1e37f5822bc3e126fb332
  • Loading branch information
qualitymanifest authored and vilemj-Viclick committed Jul 16, 2020
1 parent c5c563f commit bc9b189
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/component/handlers/edit/editOnBeforeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,6 @@ function editOnBeforeInput(
editor._latestCommittedEditorState,
);
}
if (!mustPreventNative) {
// Chrome will also split up a node into two pieces if it contains a Tab
// char, for no explicable reason. Seemingly caused by this commit:
// https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/

// in test environment, e.target is not available
const nativeSelection = (e.currentTarget
? e.currentTarget.ownerDocument.defaultView
: global
).getSelection();
// Selection is necessarily collapsed at this point due to earlier check.
if (
nativeSelection.anchorNode &&
nativeSelection.anchorNode.nodeType === Node.TEXT_NODE
) {
// See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
const parentNode = nativeSelection.anchorNode.parentNode;
mustPreventNative =
parentNode.nodeName === 'SPAN' &&
parentNode.firstChild.nodeType === Node.TEXT_NODE &&
parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
}
}
if (!mustPreventNative) {
// Let's say we have a decorator that highlights hashtags. In many cases
// we need to prevent native behavior and rerender ourselves --
Expand Down

0 comments on commit bc9b189

Please sign in to comment.