mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-06 23:36:31 +02:00
fix void selection behavior
This commit is contained in:
@@ -139,7 +139,7 @@ class Images extends React.Component {
|
|||||||
return (props) => {
|
return (props) => {
|
||||||
const { node, state } = props
|
const { node, state } = props
|
||||||
const { data } = node
|
const { data } = node
|
||||||
const isActive = state.blocks.includes(node)
|
const isActive = state.selection.isFocused && state.blocks.includes(node)
|
||||||
const src = data.get('src')
|
const src = data.get('src')
|
||||||
return <img src={src} data-active={isActive} />
|
return <img src={src} data-active={isActive} />
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
import OffsetKey from '../utils/offset-key'
|
import OffsetKey from '../utils/offset-key'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
|
||||||
import Text from './text'
|
import Text from './text'
|
||||||
import Void from './void'
|
import Void from './void'
|
||||||
import keycode from 'keycode'
|
import keycode from 'keycode'
|
||||||
@@ -303,7 +302,6 @@ class Content extends React.Component {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const el = ReactDOM.findDOMNode(this)
|
|
||||||
const { anchorNode, anchorOffset, focusNode, focusOffset } = native
|
const { anchorNode, anchorOffset, focusNode, focusOffset } = native
|
||||||
const anchor = OffsetKey.findPoint(anchorNode, anchorOffset)
|
const anchor = OffsetKey.findPoint(anchorNode, anchorOffset)
|
||||||
const focus = OffsetKey.findPoint(focusNode, focusOffset)
|
const focus = OffsetKey.findPoint(focusNode, focusOffset)
|
||||||
|
@@ -19,19 +19,19 @@ class Void extends React.Component {
|
|||||||
state: React.PropTypes.object.isRequired
|
state: React.PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
onClick(e) {
|
// onClick(e) {
|
||||||
e.preventDefault()
|
// e.preventDefault()
|
||||||
let { editor, node, state } = this.props
|
// let { editor, node, state } = this.props
|
||||||
let text = node.getTextNodes().first()
|
// let text = node.getTextNodes().first()
|
||||||
|
|
||||||
state = state
|
// state = state
|
||||||
.transform()
|
// .transform()
|
||||||
.moveToStartOf(text)
|
// .moveToStartOf(text)
|
||||||
.focus()
|
// .focus()
|
||||||
.apply()
|
// .apply()
|
||||||
|
|
||||||
editor.onChange(state)
|
// editor.onChange(state)
|
||||||
}
|
// }
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, node } = this.props
|
const { children, node } = this.props
|
||||||
@@ -41,9 +41,9 @@ class Void extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tag style={style} onClick={e => this.onClick(e)}>
|
<Tag style={style}>
|
||||||
{this.renderSpacer()}
|
{this.renderSpacer()}
|
||||||
<span contenteditable={false}>{children}</span>
|
<div contenteditable={false}>{children}</div>
|
||||||
</Tag>
|
</Tag>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,11 @@ class Void extends React.Component {
|
|||||||
renderSpacer() {
|
renderSpacer() {
|
||||||
const style = {
|
const style = {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '0px', // vertically the same, to not scroll the window
|
top: '0px',
|
||||||
left: '-10000px'
|
right: '0px',
|
||||||
|
bottom: '0px',
|
||||||
|
left: '0px',
|
||||||
|
textIndent: '-9999px'
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user