From daa7207cd6a9ed072a235aea931b46f46df924a5 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Thu, 17 Sep 2020 10:49:25 -0700 Subject: better indentation --- frontend/package.json | 1 + frontend/src/components/Inputs.js | 31 +++++++++---------------------- frontend/src/components/NewPaste.js | 6 ------ frontend/yarn.lock | 12 ++++++++++++ 4 files changed, 22 insertions(+), 28 deletions(-) (limited to 'frontend') diff --git a/frontend/package.json b/frontend/package.json index 9d0f4dc..afa7e08 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ "d3-scale": "^3.2.1", "elliptic": "^6.5.3", "file-saver": "^2.0.2", + "indent-textarea": "^2.0.2", "rc-slider": "^9.2.4", "react": "^16.13.1", "react-component-export-image": "^0.1.4", diff --git a/frontend/src/components/Inputs.js b/frontend/src/components/Inputs.js index bfa3507..3adad92 100644 --- a/frontend/src/components/Inputs.js +++ b/frontend/src/components/Inputs.js @@ -1,9 +1,10 @@ -import React, {useRef} from 'react'; +import React, {useEffect, useRef} from 'react'; import CharLimit from './decorators/CharLimit' import styled from 'styled-components' import FloatingLabel from './decorators/FloatingLabel' import Dropdown from 'react-dropdown'; import { LANGS, THEMES } from './renderers/Code'; +import * as indentation from 'indent-textarea'; const RelPositioning = styled.div` position: relative; @@ -40,45 +41,31 @@ const TitleInput = (props) => { ); } -const PasteInput = (props) => { +const PasteInput = ({content, ...props}) => { const textInput = useRef(null); - function handleKeyDown(e) { - if (e.keyCode === 9) { // tab was pressed - - // prevent autofocus on next intput - e.preventDefault(); - - // get selection start and end - const start = e.target.selectionStart - const end = e.target.selectionEnd - - props.insertTabCallback(start, end, () => { - textInput.current.focus() - textInput.current.selectionStart = textInput.current.selectionEnd + 4 - }) - } - } + useEffect(() => { + indentation.watch(textInput.current); + }, [textInput]) return ( + value={content} />