refactor onSelection to class scope

main
Mike Fix 5 years ago
parent c6ce1662b2
commit 20b56e9957

@ -68,6 +68,27 @@ class Carbon extends React.PureComponent {
} }
} }
onSelection = (ed, data) => {
const selection = data.ranges[0]
if (
selection.head.line === selection.anchor.line &&
selection.head.ch === selection.anchor.ch
) {
return (this.currentSelection = null)
}
if (selection.head.line + selection.head.ch > selection.anchor.line + selection.anchor.ch) {
this.currentSelection = {
from: selection.anchor,
to: selection.head
}
} else {
this.currentSelection = {
from: selection.head,
to: selection.anchor
}
}
}
render() { render() {
const config = { ...DEFAULT_SETTINGS, ...this.props.config } const config = { ...DEFAULT_SETTINGS, ...this.props.config }
@ -140,31 +161,7 @@ class Carbon extends React.PureComponent {
options={options} options={options}
onBeforeChange={this.onBeforeChange} onBeforeChange={this.onBeforeChange}
onGutterClick={this.props.onGutterClick} onGutterClick={this.props.onGutterClick}
onSelection={(ed, data) => { onSelection={this.onSelection}
const selection = data.ranges[0]
if (
selection.head.line === selection.anchor.line &&
selection.head.ch === selection.anchor.ch
) {
return (this.currentSelection = null)
}
if (
selection.head.line + selection.head.ch >
selection.anchor.line + selection.anchor.ch
) {
this.currentSelection = {
from: selection.anchor,
to: selection.head
}
} else {
this.currentSelection = {
from: selection.head,
to: selection.anchor
}
}
}}
/> />
{config.watermark && <Watermark light={light} />} {config.watermark && <Watermark light={light} />}
<div className="container-bg"> <div className="container-bg">

Loading…
Cancel
Save