mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 15:02:51 +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) {
|
||||
change.call(unwrapLink)
|
||||
} else if (value.isExpanded) {
|
||||
} else if (value.selection.isExpanded) {
|
||||
const href = window.prompt('Enter the URL of the link:')
|
||||
|
||||
if (href === null) {
|
||||
return
|
||||
}
|
||||
|
||||
change.call(wrapLink, href)
|
||||
} else {
|
||||
const href = window.prompt('Enter the URL of the link:')
|
||||
|
||||
if (href === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const text = window.prompt('Enter the text for the link:')
|
||||
|
||||
if (text === null) {
|
||||
return
|
||||
}
|
||||
|
||||
change
|
||||
.insertText(text)
|
||||
.extend(0 - text.length)
|
||||
.moveFocusBackward(text.length)
|
||||
.call(wrapLink, href)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user