Skip to content

Commit

Permalink
Partially revert 0463a17 (#908). Fixes #999.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Jan 14, 2021
1 parent 13e296c commit edb57d0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/Editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ const Editable = ({ disabled, isEditing, simplePath, path, cursorOffset, showCon
// using useRef hook to store throttled function so that it can persist even between component re-renders, so that throttle.flush method can be used properly
const throttledChangeRef = useRef(_.throttle(thoughtChangeHandler, EDIT_THROTTLE, { leading: false }))

/** Set the selection to the current Editable at the cursor offset. */
const setSelectionToCursorOffset = () => {
if (contentRef.current) {
setSelection(contentRef.current, { offset: cursorOffset || state.cursorOffset || 0 })
}
}

useEffect(() => {
const { editing, noteFocus, dragHold } = state
const editMode = !isTouch || editing
Expand All @@ -318,7 +325,20 @@ const Editable = ({ disabled, isEditing, simplePath, path, cursorOffset, showCon
(state.cursorOffset !== null || !window.getSelection()?.focusNode) &&
!dragHold
) {
setSelection(contentRef.current, { offset: cursorOffset || state.cursorOffset || 0 })
/*
Mobile Safari: Auto-Capitalization is broken if the selection is set synchronously.
- When a new thought is created, the Shift key should be on when Auto-Capitalization is enabled.
- Only breaks on Enter or Backspace, not gesture.
- Even stranger, the issue only showed up when newThought was converted to a reducer (ecc3b3be).
- For some reason, setTimeout fixes it.
- Do not call asyncFocus as it causes an infinite loop (#908)
*/
if (isTouch && isSafari()) {
setTimeout(setSelectionToCursorOffset)
}
else {
setSelectionToCursorOffset()
}
}

/** Flushes pending edits. */
Expand Down

0 comments on commit edb57d0

Please sign in to comment.