diff options
| author | jackyzha0 <[email protected]> | 2020-09-17 10:49:25 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-09-17 10:49:25 -0700 |
| commit | daa7207cd6a9ed072a235aea931b46f46df924a5 (patch) | |
| tree | 8ff5374bd2ef9ead608b065938b5ae74c03611e1 /frontend/src | |
| parent | patch bad render mode for non latex and markdown (diff) | |
| download | ctrl-v-daa7207cd6a9ed072a235aea931b46f46df924a5.tar.xz ctrl-v-daa7207cd6a9ed072a235aea931b46f46df924a5.zip | |
better indentation
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/components/Inputs.js | 31 | ||||
| -rw-r--r-- | frontend/src/components/NewPaste.js | 6 |
2 files changed, 9 insertions, 28 deletions
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 ( <RelPositioning> <FloatingLabel label="content" id={props.id} - value={props.content} /> + value={content} /> <textarea name="content" readOnly={props.readOnly} placeholder="Paste your text here" - value={props.content} + value={content} id={props.id} ref={textInput} required onChange={props.onChange} - onKeyDown={handleKeyDown} className="lt-shadow" /> <CharLimit - content={props.content} + content={content} maxLength={props.maxLength} /> </RelPositioning> ); diff --git a/frontend/src/components/NewPaste.js b/frontend/src/components/NewPaste.js index f778a05..ff945a0 100644 --- a/frontend/src/components/NewPaste.js +++ b/frontend/src/components/NewPaste.js @@ -77,15 +77,9 @@ const NewPaste = () => { } } - function insertTab(start, end, callback) { - setContent(content.substring(0, start) + ' ' + content.substring(end)) - callback() - } - function renderPreview() { const pasteInput = <PasteInput onChange={(e) => { setContent(e.target.value) }} - insertTabCallback={insertTab} content={content} maxLength="100000" id="pasteInput" /> |