From 20b56e995781b2c0141d520831cdfeb2bf0d7389 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Thu, 8 Aug 2019 16:53:27 -0700 Subject: [PATCH] refactor onSelection to class scope --- components/Carbon.js | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/components/Carbon.js b/components/Carbon.js index 2c4acaf..8ca1198 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -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() { const config = { ...DEFAULT_SETTINGS, ...this.props.config } @@ -140,31 +161,7 @@ class Carbon extends React.PureComponent { options={options} onBeforeChange={this.onBeforeChange} onGutterClick={this.props.onGutterClick} - 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 - } - } - }} + onSelection={this.onSelection} /> {config.watermark && }