mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 08:11:53 +02:00
fix(example/links): a few fixes for the links example (#2175)
* Correctly use the selection * check whether the user cancelled the prompt * use `moveFocusBackward`
This commit is contained in:
committed by
Ian Storm Taylor
parent
222f746e85
commit
462244600d
@@ -133,16 +133,30 @@ class Links extends React.Component {
|
|||||||
|
|
||||||
if (hasLinks) {
|
if (hasLinks) {
|
||||||
change.call(unwrapLink)
|
change.call(unwrapLink)
|
||||||
} else if (value.isExpanded) {
|
} else if (value.selection.isExpanded) {
|
||||||
const href = window.prompt('Enter the URL of the link:')
|
const href = window.prompt('Enter the URL of the link:')
|
||||||
|
|
||||||
|
if (href === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
change.call(wrapLink, href)
|
change.call(wrapLink, href)
|
||||||
} else {
|
} else {
|
||||||
const href = window.prompt('Enter the URL of the link:')
|
const href = window.prompt('Enter the URL of the link:')
|
||||||
|
|
||||||
|
if (href === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const text = window.prompt('Enter the text for the link:')
|
const text = window.prompt('Enter the text for the link:')
|
||||||
|
|
||||||
|
if (text === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
change
|
change
|
||||||
.insertText(text)
|
.insertText(text)
|
||||||
.extend(0 - text.length)
|
.moveFocusBackward(text.length)
|
||||||
.call(wrapLink, href)
|
.call(wrapLink, href)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user