Repository: ianstormtaylor/slate
File: packages/slate-react/src/components/editable.tsx (TypeScript)

Code before:

        let native = false
        if (
          type === 'insertText' &&
          selection &&
          Range.isCollapsed(selection) &&
          // Only do it for single character a-z or space for now.
          // Long-press events (hold a + press 4 = ä) to choose a special character otherwise
          // causes duplicate inserts.
          event.data &&
          event.data.length === 1 &&
          /[a-z ]/i.test(event.data) &&
          // Chrome seems to have issues correctly editing the start of nodes.
          // I see this when there is an inline element, like a link, and you select
          // right after it (the start of the next node).
          selection.anchor.offset !== 0
        ) {
          native = true

          // Skip native if there are marks, as that means
          // `insertText` will insert a node, not just text.
          if (editor.marks) {
            native = false
          }

          // and because of the selection moving in `insertText` (create-editor.tx).
          const { anchor } = selection
          const inline = Editor.above(editor, {
            at: anchor,
            match: n => Editor.isInline(editor, n),
            mode: 'highest',
          })
          if (inline) {
            const [, inlinePath] = inline

            if (Editor.isEnd(editor, selection.anchor, inlinePath)) {
              native = false
            }
          }
        }

        if (!native) {
          event.preventDefault()
        }

        // COMPAT: For the deleting forward/backward input types we don't want
        // to change the selection because it is the range that will be deleted,
        // and those commands determine that for themselves.
        if (!type.startsWith('delete') || type.startsWith('deleteBy')) {
          const [targetRange] = (event as any).getTargetRanges()


Review comment (suggestion):
```suggestion
          // and because of the selection moving in `insertText` (create-editor.ts).
```

Code after:

        let native = false
        if (
          type === 'insertText' &&
          selection &&
          Range.isCollapsed(selection) &&
          // Only use native character insertion for single characters a-z or space for now.
          // Long-press events (hold a + press 4 = ä) to choose a special character otherwise
          // causes duplicate inserts.
          event.data &&
          event.data.length === 1 &&
          /[a-z ]/i.test(event.data) &&
          // Chrome seems to have issues correctly editing the start of nodes.
          // When there is an inline element, e.g. a link, and you select
          // right after it (the start of the next node).
          selection.anchor.offset !== 0
        ) {
          native = true

          // Skip native if there are marks, as
          // `insertText` will insert a node, not just text.
          if (editor.marks) {
            native = false
          }

          // and because of the selection moving in `insertText` (create-editor.ts).
          const { anchor } = selection
          const inline = Editor.above(editor, {
            at: anchor,
            match: n => Editor.isInline(editor, n),
            mode: 'highest',
          })
          if (inline) {
            const [, inlinePath] = inline

            if (Editor.isEnd(editor, selection.anchor, inlinePath)) {
              native = false
            }
          }
        }

        if (!native) {
          event.preventDefault()
        }

        // COMPAT: For the deleting forward/backward input types we don't want
        // to change the selection because it is the range that will be deleted,
        // and those commands determine that for themselves.
        if (!type.startsWith('delete') || type.startsWith('deleteBy')) {
          const [targetRange] = (event as any).getTargetRanges()