CodeEditor bugfixes

* fix typing space character
* hide cursor when editor doesn't have user focus
* show help text any time editor is in focus
* fix content shifting when help text appears/disappears
* remove 80 character "print limit" line
This commit is contained in:
Keith J. Grant
2021-03-11 16:20:05 -08:00
parent 6f7a717664
commit 4ea7c8a534

View File

@@ -15,11 +15,16 @@ const PADDING = 12;
const FocusWrapper = styled.div` const FocusWrapper = styled.div`
&& + .keyboard-help-text { && + .keyboard-help-text {
display: none; opacity: 0;
transition: opacity 0.1s linear;
} }
&:focus-within + .keyboard-help-text { &:focus-within + .keyboard-help-text {
display: block; opacity: 1;
}
& .ace_hidden-cursors .ace_cursor {
opacity: 0;
} }
`; `;
@@ -71,7 +76,6 @@ function CodeEditor({
className, className,
i18n, i18n,
}) { }) {
const [isKeyboardFocused, setIsKeyboardFocused] = useState(false);
const wrapper = useRef(null); const wrapper = useRef(null);
const editor = useRef(null); const editor = useRef(null);
@@ -86,10 +90,7 @@ function CodeEditor({
); );
const listen = useCallback(event => { const listen = useCallback(event => {
if ( if (wrapper.current === document.activeElement && event.key === 'Enter') {
(wrapper.current === document.activeElement && event.key === 'Enter') ||
event.key === ' '
) {
const editorInput = editor.current.refEditor?.querySelector('textarea'); const editorInput = editor.current.refEditor?.querySelector('textarea');
if (!editorInput) { if (!editorInput) {
return; return;
@@ -119,18 +120,7 @@ function CodeEditor({
return ( return (
<> <>
<FocusWrapper <FocusWrapper ref={wrapper} tabIndex={readOnly ? -1 : 0}>
ref={wrapper}
tabIndex={readOnly ? -1 : 0}
onFocus={e => {
if (e.target === e.currentTarget) {
setIsKeyboardFocused(true);
}
if (e.target.className.includes('ace_scrollbar')) {
setIsKeyboardFocused(false);
}
}}
>
<AceEditor <AceEditor
mode={aceModes[mode] || 'text'} mode={aceModes[mode] || 'text'}
className={`pf-c-form-control ${className}`} className={`pf-c-form-control ${className}`}
@@ -148,6 +138,7 @@ function CodeEditor({
highlightActiveLine: !readOnly, highlightActiveLine: !readOnly,
highlightGutterLine: !readOnly, highlightGutterLine: !readOnly,
useWorker: false, useWorker: false,
showPrintMargin: false,
}} }}
commands={[ commands={[
{ {
@@ -168,7 +159,7 @@ function CodeEditor({
ref={editor} ref={editor}
/> />
</FocusWrapper> </FocusWrapper>
{isKeyboardFocused && !readOnly && ( {!readOnly && (
<div <div
className="pf-c-form__helper-text keyboard-help-text" className="pf-c-form__helper-text keyboard-help-text"
aria-live="polite" aria-live="polite"