diff options
| author | jackyzha0 <[email protected]> | 2020-09-17 10:15:52 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-09-17 10:15:52 -0700 |
| commit | 620bb9e3bd8faffebfb077a51bbadb03134994b6 (patch) | |
| tree | 3a14f10dc4b9aea680754656a2717177ddf03734 /frontend/src | |
| parent | Merge pull request #59 from jackyzha0/patch-qol (diff) | |
| download | ctrl-v-620bb9e3bd8faffebfb077a51bbadb03134994b6.tar.xz ctrl-v-620bb9e3bd8faffebfb077a51bbadb03134994b6.zip | |
patch bad render mode for non latex and markdown
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/components/Inputs.js | 13 | ||||
| -rw-r--r-- | frontend/src/components/NewPaste.js | 3 | ||||
| -rw-r--r-- | frontend/src/components/ViewPaste.js | 6 |
3 files changed, 15 insertions, 7 deletions
diff --git a/frontend/src/components/Inputs.js b/frontend/src/components/Inputs.js index d22e23f..bfa3507 100644 --- a/frontend/src/components/Inputs.js +++ b/frontend/src/components/Inputs.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useRef} from 'react'; import CharLimit from './decorators/CharLimit' import styled from 'styled-components' import FloatingLabel from './decorators/FloatingLabel' @@ -41,6 +41,8 @@ const TitleInput = (props) => { } const PasteInput = (props) => { + const textInput = useRef(null); + function handleKeyDown(e) { if (e.keyCode === 9) { // tab was pressed @@ -51,10 +53,10 @@ const PasteInput = (props) => { const start = e.target.selectionStart const end = e.target.selectionEnd - props.insertTabCallback(start, end) - - // set cursor position to be at start - e.target.selectionEnd = end + 4; + props.insertTabCallback(start, end, () => { + textInput.current.focus() + textInput.current.selectionStart = textInput.current.selectionEnd + 4 + }) } } @@ -70,6 +72,7 @@ const PasteInput = (props) => { placeholder="Paste your text here" value={props.content} id={props.id} + ref={textInput} required onChange={props.onChange} onKeyDown={handleKeyDown} diff --git a/frontend/src/components/NewPaste.js b/frontend/src/components/NewPaste.js index b276db8..f778a05 100644 --- a/frontend/src/components/NewPaste.js +++ b/frontend/src/components/NewPaste.js @@ -77,8 +77,9 @@ const NewPaste = () => { } } - function insertTab(start, end) { + function insertTab(start, end, callback) { setContent(content.substring(0, start) + ' ' + content.substring(end)) + callback() } function renderPreview() { diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js index b2e1ba5..5f9a962 100644 --- a/frontend/src/components/ViewPaste.js +++ b/frontend/src/components/ViewPaste.js @@ -23,9 +23,13 @@ const ViewPaste = (props) => { const [validPass, setValidPass] = useState(false); const [expiry, setExpiry] = useState(''); const [theme, setTheme] = useState('atom'); - const [isRenderMode, setIsRenderMode] = useState(true); + const [isRenderMode, setIsRenderMode] = useState(false); const [language, setLanguage] = useState(LANGS.raw); + useEffect(() => { + setIsRenderMode(language === 'latex' || language === 'markdown') + }, [language]) + const ErrorLabelRef = useRef(null); const ComponentRef = useRef(null); |