Fixed an issue where the value in the find box is not updating with selected text in editor if find is already open and re-triggered. #7775
parent
b4e4b9d498
commit
654dc0e2d7
|
@ -61,21 +61,19 @@ CopyButton.propTypes = {
|
||||||
|
|
||||||
export default function CodeMirror({className, currEditor, showCopyBtn=false, customKeyMap=[], onTextSelect, ...props}) {
|
export default function CodeMirror({className, currEditor, showCopyBtn=false, customKeyMap=[], onTextSelect, ...props}) {
|
||||||
const editor = useRef();
|
const editor = useRef();
|
||||||
const [[showFind, isReplace], setShowFind] = useState([false, false]);
|
const [[showFind, isReplace, findKey], setShowFind] = useState([false, false, false]);
|
||||||
const [showGoto, setShowGoto] = useState(false);
|
const [showGoto, setShowGoto] = useState(false);
|
||||||
const [showCopy, setShowCopy] = useState(false);
|
const [showCopy, setShowCopy] = useState(false);
|
||||||
|
|
||||||
const finalCustomKeyMap = useMemo(()=>[{
|
const finalCustomKeyMap = useMemo(()=>[{
|
||||||
key: 'Mod-f', run: () => {
|
key: 'Mod-f', run: () => {
|
||||||
setShowFind([false, false]);
|
setShowFind(prevVal => [true, false, !prevVal[2]]);
|
||||||
setShowFind([true, false]);
|
|
||||||
},
|
},
|
||||||
preventDefault: true,
|
preventDefault: true,
|
||||||
stopPropagation: true,
|
stopPropagation: true,
|
||||||
}, {
|
}, {
|
||||||
key: 'Mod-Alt-f', run: () => {
|
key: 'Mod-Alt-f', run: () => {
|
||||||
setShowFind([false, false]);
|
setShowFind(prevVal => [true, true, !prevVal[2]]);
|
||||||
setShowFind([true, true]);
|
|
||||||
},
|
},
|
||||||
preventDefault: true,
|
preventDefault: true,
|
||||||
stopPropagation: true,
|
stopPropagation: true,
|
||||||
|
@ -89,7 +87,7 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu
|
||||||
...customKeyMap], [customKeyMap]);
|
...customKeyMap], [customKeyMap]);
|
||||||
|
|
||||||
const closeFind = () => {
|
const closeFind = () => {
|
||||||
setShowFind([false, false]);
|
setShowFind([false, false, false]);
|
||||||
editor.current?.focus();
|
editor.current?.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -139,7 +137,7 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu
|
||||||
<Root className={[className].join(' ')} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} >
|
<Root className={[className].join(' ')} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} >
|
||||||
<Editor currEditor={currEditorWrap} customKeyMap={finalCustomKeyMap} {...props} />
|
<Editor currEditor={currEditorWrap} customKeyMap={finalCustomKeyMap} {...props} />
|
||||||
{showCopy && <CopyButton editor={editor.current} />}
|
{showCopy && <CopyButton editor={editor.current} />}
|
||||||
<FindDialog editor={editor.current} show={showFind} replace={isReplace} onClose={closeFind} />
|
<FindDialog key={findKey} editor={editor.current} show={showFind} replace={isReplace} onClose={closeFind} />
|
||||||
<GotoDialog editor={editor.current} show={showGoto} onClose={closeGoto} />
|
<GotoDialog editor={editor.current} show={showGoto} onClose={closeGoto} />
|
||||||
</Root>
|
</Root>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue