From 7f8ba201cc1d61cb80f2a85975f9a817fbe08577 Mon Sep 17 00:00:00 2001 From: flurryrush Date: Fri, 10 May 2019 09:58:25 +0200 Subject: [PATCH 1/3] Hide side toolbar when editor does not have focus. --- src/components/addbutton.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/addbutton.js b/src/components/addbutton.js index 8ba083ab..45551d94 100644 --- a/src/components/addbutton.js +++ b/src/components/addbutton.js @@ -34,6 +34,7 @@ export default class AddButton extends React.Component { const { editorState } = newProps; const contentState = editorState.getCurrentContent(); const selectionState = editorState.getSelection(); + const hasFocus = editorState.getSelection().getHasFocus(); if (!selectionState.isCollapsed() || selectionState.anchorKey !== selectionState.focusKey || contentState.getBlockForKey(selectionState.getAnchorKey()).getType().indexOf('atomic') >= 0) { // console.log('no sel'); this.hideBlock(); @@ -59,7 +60,7 @@ export default class AddButton extends React.Component { this.hideBlock(); } else { this.setState({ - visible: true, + visible: true && hasFocus, }); } return; @@ -97,6 +98,8 @@ export default class AddButton extends React.Component { } findNode() { + const { editorState } = this.props; + const hasFocus = editorState.getSelection().getHasFocus(); // eslint-disable-next-line no-undef const node = getSelectedBlockNode(window); if (node === this.node) { @@ -114,7 +117,7 @@ export default class AddButton extends React.Component { // const rect = node.getBoundingClientRect(); this.node = node; this.setState({ - visible: true, + visible: true && hasFocus, style: { top: node.offsetTop - 3, }, From 6d3f29336eb04646fa71cc019358c953875be434 Mon Sep 17 00:00:00 2001 From: flurryrush Date: Tue, 21 May 2019 10:17:17 +0200 Subject: [PATCH 2/3] Use hasFocus directly, and'ing with true makes no sense. --- src/components/addbutton.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/addbutton.js b/src/components/addbutton.js index 45551d94..df3ed152 100644 --- a/src/components/addbutton.js +++ b/src/components/addbutton.js @@ -60,7 +60,7 @@ export default class AddButton extends React.Component { this.hideBlock(); } else { this.setState({ - visible: true && hasFocus, + visible: hasFocus, }); } return; @@ -117,7 +117,7 @@ export default class AddButton extends React.Component { // const rect = node.getBoundingClientRect(); this.node = node; this.setState({ - visible: true && hasFocus, + visible: hasFocus, style: { top: node.offsetTop - 3, }, From 62c4c09ed50dca4734d7a28c1a323e9d0e9a87a1 Mon Sep 17 00:00:00 2001 From: flurryrush Date: Wed, 12 Jun 2019 09:19:12 +0200 Subject: [PATCH 3/3] Revert commits using hasFocus() to hide side toolbar button --- src/components/addbutton.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/addbutton.js b/src/components/addbutton.js index df3ed152..8ba083ab 100644 --- a/src/components/addbutton.js +++ b/src/components/addbutton.js @@ -34,7 +34,6 @@ export default class AddButton extends React.Component { const { editorState } = newProps; const contentState = editorState.getCurrentContent(); const selectionState = editorState.getSelection(); - const hasFocus = editorState.getSelection().getHasFocus(); if (!selectionState.isCollapsed() || selectionState.anchorKey !== selectionState.focusKey || contentState.getBlockForKey(selectionState.getAnchorKey()).getType().indexOf('atomic') >= 0) { // console.log('no sel'); this.hideBlock(); @@ -60,7 +59,7 @@ export default class AddButton extends React.Component { this.hideBlock(); } else { this.setState({ - visible: hasFocus, + visible: true, }); } return; @@ -98,8 +97,6 @@ export default class AddButton extends React.Component { } findNode() { - const { editorState } = this.props; - const hasFocus = editorState.getSelection().getHasFocus(); // eslint-disable-next-line no-undef const node = getSelectedBlockNode(window); if (node === this.node) { @@ -117,7 +114,7 @@ export default class AddButton extends React.Component { // const rect = node.getBoundingClientRect(); this.node = node; this.setState({ - visible: hasFocus, + visible: true, style: { top: node.offsetTop - 3, },