From feaad7e7cda6df2ac480aea41b4f4bde0ff8dc37 Mon Sep 17 00:00:00 2001 From: Stan Gurenkov Date: Wed, 24 Apr 2019 17:24:15 -0700 Subject: [PATCH] Fix selection being reset incorrectly after combination of events (#2686) * Fix selection being reset incorrectly after combination of events If mouseDown happens inside editor container and mouseUp outside it, then programmatically calling editor.focus() after that will mess up the selection * Update after.js --- packages/slate-react/src/plugins/after.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/slate-react/src/plugins/after.js b/packages/slate-react/src/plugins/after.js index 353d0be9e..9071b0be4 100644 --- a/packages/slate-react/src/plugins/after.js +++ b/packages/slate-react/src/plugins/after.js @@ -634,6 +634,11 @@ function AfterPlugin(options = {}) { const window = getWindow(event.target) const selection = window.getSelection() setSelectionFromDom(window, editor, selection) + + // COMPAT: reset the `isMouseDown` state here in case a `mouseup` event + // happens outside the editor. This is needed for `onFocus` handling. + isMouseDown = false + next() }