From 37debfdbade67ac94cc1589c3cd7bddbffc9680c Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Thu, 8 Aug 2019 16:59:54 -0700 Subject: [PATCH] refactor onMouseUp to class scope --- components/Carbon.js | 45 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/components/Carbon.js b/components/Carbon.js index 8f4da83..50d99f9 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -89,6 +89,25 @@ class Carbon extends React.PureComponent { } } + onMouseUp = () => { + if (this.currentSelection) { + const { editor } = this.props.editorRef.current + const startPos = editor.charCoords(this.currentSelection.from, 'local') + const endPos = editor.charCoords(this.currentSelection.to, 'local') + const startWindowPos = editor.charCoords(this.currentSelection.from, 'window') + const endWindowPos = editor.charCoords(this.currentSelection.to, 'window') + const top = + Math.max(startWindowPos.bottom, endWindowPos.bottom) - + this.props.innerRef.current.getBoundingClientRect().top - + 3 + const left = (startPos.left + endPos.right) / 2 + this.setState({ selectionAt: { top, left } }) + // this.currentSelection = null + } else { + this.setState({ selectionAt: null }) + } + } + render() { const config = { ...DEFAULT_SETTINGS, ...this.props.config } @@ -122,31 +141,7 @@ class Carbon extends React.PureComponent { /* eslint-disable jsx-a11y/no-static-element-interactions */ const content = ( -
{ - if (this.currentSelection) { - const { editor } = this.props.editorRef.current - - const startPos = editor.charCoords(this.currentSelection.from, 'local') - const endPos = editor.charCoords(this.currentSelection.to, 'local') - - const startWindowPos = editor.charCoords(this.currentSelection.from, 'window') - const endWindowPos = editor.charCoords(this.currentSelection.to, 'window') - - const top = - Math.max(startWindowPos.bottom, endWindowPos.bottom) - - this.props.innerRef.current.getBoundingClientRect().top - - 3 - const left = (startPos.left + endPos.right) / 2 - - this.setState({ selectionAt: { top, left } }) - // this.currentSelection = null - } else { - this.setState({ selectionAt: null }) - } - }} - > +
{config.windowControls ? (