Skip to content

Commit

Permalink
🐝 Fix #2518
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Jul 17, 2023
1 parent 0071ec1 commit 9c052d3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,23 @@ export const CellInput = ({
// Remove selection on blur
EditorView.domEventHandlers({
blur: (event, view) => {
// collapse the selection into a single point
view.dispatch({
selection: {
anchor: view.state.selection.main.head,
},
scrollIntoView: false,
})
// and blur the DOM again (because the previous transaction might have re-focused it)
view.contentDOM.blur()

set_cm_forced_focus(null)
// it turns out that this condition is true *exactly* if and only if the blur event was triggered by blurring the window
let caused_by_window_blur = document.activeElement === view.contentDOM

if (!caused_by_window_blur) {
// then it's caused by focusing something other than this cell in the editor.
// in this case, we want to collapse the selection into a single point, for aesthetic reasons.
view.dispatch({
selection: {
anchor: view.state.selection.main.head,
},
scrollIntoView: false,
})
// and blur the DOM again (because the previous transaction might have re-focused it)
view.contentDOM.blur()

set_cm_forced_focus(null)
}
},
}),
pluto_paste_plugin({
Expand Down

0 comments on commit 9c052d3

Please sign in to comment.