From 92de0f466454f3cad3b5b5baabe4f7f2ef7c8705 Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Fri, 14 Sep 2018 20:37:27 +0200 Subject: [PATCH] Scroll text editor error indication into view through a button Resolves https://github.com/magjac/graphviz-visual-editor/issues/46 --- src/TextEditor.js | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/TextEditor.js b/src/TextEditor.js index 950e76a0..68b9dc4d 100644 --- a/src/TextEditor.js +++ b/src/TextEditor.js @@ -1,7 +1,17 @@ import React from 'react'; +import { withStyles } from '@material-ui/core/styles'; import AceEditor from 'react-ace'; import 'brace/mode/dot'; import 'brace/theme/github'; +import IconButton from '@material-ui/core/IconButton'; +import ErrorOutline from '@material-ui/icons/ErrorOutline'; + +const styles = { + errorButton: { + position: 'absolute', + top: 'calc(64px + 12px)', + }, +}; class TextEditor extends React.Component { @@ -22,7 +32,12 @@ class TextEditor extends React.Component { this.editor = editor; }; + handleErrorButtonClick = (event) => { + this.editor.scrollToLine(this.props.error.line - 1, true); + }; + render() { + const { classes } = this.props; var annotations = null; if (this.props.error) { annotations = [{ @@ -58,9 +73,18 @@ class TextEditor extends React.Component { className: 'ace_selected-word', type: 'background', })); - + // FIXME: There must be a better way... + let scrollbarWidth = 0; + if (this.div) { + const scrollbarDiv = this.div.querySelector('div.ace_scrollbar-v'); + const hasScrollbar = scrollbarDiv && scrollbarDiv.style['display'] !== 'none'; + if (hasScrollbar) { + const scrollbarInnerDiv = scrollbarDiv.querySelector('div.ace_scrollbar-inner'); + scrollbarWidth = scrollbarInnerDiv.clientWidth - 5; + } + } return ( -
+
this.div = div}> + + +
); } } -export default TextEditor; +export default withStyles(styles)(TextEditor);