1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-07-30 20:10:24 +02:00

fix void selection behavior

This commit is contained in:
Ian Storm Taylor
2016-07-01 13:03:22 -07:00
parent 1c8986019d
commit aa8e295a2d
3 changed files with 19 additions and 18 deletions

View File

@@ -139,7 +139,7 @@ class Images extends React.Component {
return (props) => {
const { node, state } = props
const { data } = node
const isActive = state.blocks.includes(node)
const isActive = state.selection.isFocused && state.blocks.includes(node)
const src = data.get('src')
return <img src={src} data-active={isActive} />
}

View File

@@ -1,7 +1,6 @@
import OffsetKey from '../utils/offset-key'
import React from 'react'
import ReactDOM from 'react-dom'
import Text from './text'
import Void from './void'
import keycode from 'keycode'
@@ -303,7 +302,6 @@ class Content extends React.Component {
return
}
const el = ReactDOM.findDOMNode(this)
const { anchorNode, anchorOffset, focusNode, focusOffset } = native
const anchor = OffsetKey.findPoint(anchorNode, anchorOffset)
const focus = OffsetKey.findPoint(focusNode, focusOffset)

View File

@@ -19,19 +19,19 @@ class Void extends React.Component {
state: React.PropTypes.object.isRequired
};
onClick(e) {
e.preventDefault()
let { editor, node, state } = this.props
let text = node.getTextNodes().first()
// onClick(e) {
// e.preventDefault()
// let { editor, node, state } = this.props
// let text = node.getTextNodes().first()
state = state
.transform()
.moveToStartOf(text)
.focus()
.apply()
// state = state
// .transform()
// .moveToStartOf(text)
// .focus()
// .apply()
editor.onChange(state)
}
// editor.onChange(state)
// }
render() {
const { children, node } = this.props
@@ -41,9 +41,9 @@ class Void extends React.Component {
}
return (
<Tag style={style} onClick={e => this.onClick(e)}>
<Tag style={style}>
{this.renderSpacer()}
<span contenteditable={false}>{children}</span>
<div contenteditable={false}>{children}</div>
</Tag>
)
}
@@ -51,8 +51,11 @@ class Void extends React.Component {
renderSpacer() {
const style = {
position: 'absolute',
top: '0px', // vertically the same, to not scroll the window
left: '-10000px'
top: '0px',
right: '0px',
bottom: '0px',
left: '0px',
textIndent: '-9999px'
}
return (