mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-21 22:02:05 +02:00
Various fixes for selections (#610)
* transforms/on-selection: fix deprecation warnings * Check for selection with selection.isCollapsed (not .rangeCount)
This commit is contained in:
parent
77ffcaae66
commit
a5550ad23a
@ -221,7 +221,7 @@ function Plugin(options = {}) {
|
||||
function onCutOrCopy(e, data, state) {
|
||||
const window = getWindow(e.target)
|
||||
const native = window.getSelection()
|
||||
if (!native.rangeCount) return
|
||||
if (native.isCollapsed) return
|
||||
|
||||
const { fragment } = data
|
||||
const encoded = Base64.serializeNode(fragment)
|
||||
|
@ -35,7 +35,7 @@ export function collapseToEndOfNextBlock(transform) {
|
||||
const { document, selection } = state
|
||||
const blocks = document.getBlocksAtRange(selection)
|
||||
const last = blocks.last()
|
||||
const next = document.getNextBlock(last)
|
||||
const next = document.getNextBlock(last.key)
|
||||
if (!next) return
|
||||
|
||||
const sel = selection.collapseToEndOf(next)
|
||||
@ -53,7 +53,7 @@ export function collapseToEndOfNextText(transform) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTextsAtRange(selection)
|
||||
const last = texts.last()
|
||||
const next = document.getNextText(last)
|
||||
const next = document.getNextText(last.key)
|
||||
if (!next) return
|
||||
|
||||
const sel = selection.collapseToEndOf(next)
|
||||
@ -71,7 +71,7 @@ export function collapseToEndOfPreviousBlock(transform) {
|
||||
const { document, selection } = state
|
||||
const blocks = document.getBlocksAtRange(selection)
|
||||
const first = blocks.first()
|
||||
const previous = document.getPreviousBlock(first)
|
||||
const previous = document.getPreviousBlock(first.key)
|
||||
if (!previous) return
|
||||
|
||||
const sel = selection.collapseToEndOf(previous)
|
||||
@ -89,7 +89,7 @@ export function collapseToEndOfPreviousText(transform) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTextsAtRange(selection)
|
||||
const first = texts.first()
|
||||
const previous = document.getPreviousText(first)
|
||||
const previous = document.getPreviousText(first.key)
|
||||
if (!previous) return
|
||||
|
||||
const sel = selection.collapseToEndOf(previous)
|
||||
@ -107,7 +107,7 @@ export function collapseToStartOfNextBlock(transform) {
|
||||
const { document, selection } = state
|
||||
const blocks = document.getBlocksAtRange(selection)
|
||||
const last = blocks.last()
|
||||
const next = document.getNextBlock(last)
|
||||
const next = document.getNextBlock(last.key)
|
||||
if (!next) return
|
||||
|
||||
const sel = selection.collapseToStartOf(next)
|
||||
@ -125,7 +125,7 @@ export function collapseToStartOfNextText(transform) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTextsAtRange(selection)
|
||||
const last = texts.last()
|
||||
const next = document.getNextText(last)
|
||||
const next = document.getNextText(last.key)
|
||||
if (!next) return
|
||||
|
||||
const sel = selection.collapseToStartOf(next)
|
||||
@ -143,7 +143,7 @@ export function collapseToStartOfPreviousBlock(transform) {
|
||||
const { document, selection } = state
|
||||
const blocks = document.getBlocksAtRange(selection)
|
||||
const first = blocks.first()
|
||||
const previous = document.getPreviousBlock(first)
|
||||
const previous = document.getPreviousBlock(first.key)
|
||||
if (!previous) return
|
||||
|
||||
const sel = selection.collapseToStartOf(previous)
|
||||
@ -161,7 +161,7 @@ export function collapseToStartOfPreviousText(transform) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTextsAtRange(selection)
|
||||
const first = texts.first()
|
||||
const previous = document.getPreviousText(first)
|
||||
const previous = document.getPreviousText(first.key)
|
||||
if (!previous) return
|
||||
|
||||
const sel = selection.collapseToStartOf(previous)
|
||||
|
Loading…
x
Reference in New Issue
Block a user