Skip to content

Commit

Permalink
Desktop: Dev fix: Only disable editor toolbar in preview mode
Browse files Browse the repository at this point in the history
Reverts 4682619

Disabling the toolbar when the editor is not in focus means it
was disabled when trying to click on one of the button, because
the editor loses focus before the click event is processed.
  • Loading branch information
laurent22 committed Jun 3, 2020
1 parent 4fd20b1 commit f4092c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
11 changes: 4 additions & 7 deletions ElectronClient/gui/NoteEditor/NoteBody/AceEditor/AceEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { commandAttachFileToBody, handlePasteEvent } from '../../utils/resourceH
import { ScrollOptions, ScrollOptionTypes } from '../../utils/types';
import { textOffsetToCursorPosition, useScrollHandler, useRootWidth, usePrevious, lineLeftSpaces, selectionRange, selectionRangeCurrentLine, selectionRangePreviousLine, currentTextOffset, textOffsetSelection, selectedText } from './utils';
import useListIdent from './utils/useListIdent';
import useFocus from './utils/useFocus';
import Toolbar from './Toolbar';
import styles_ from './styles';
import { RenderedBody, defaultRenderedBody } from './utils/types';
Expand Down Expand Up @@ -553,8 +552,6 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) {
}
}, [props.searchMarkers, renderedBody]);

const { focused, onBlur, onFocus } = useFocus();

const cellEditorStyle = useMemo(() => {
const output = { ...styles.cellEditor };
if (!props.visiblePanes.includes('editor')) {
Expand Down Expand Up @@ -590,6 +587,8 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) {
return output;
}, [styles.cellViewer, props.visiblePanes]);

const editorReadOnly = props.visiblePanes.indexOf('editor') < 0;

function renderEditor() {
// Need to hard-code the editor width, otherwise various bugs pops up
let width = 0;
Expand All @@ -603,13 +602,11 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) {
value={props.content}
mode={props.contentMarkupLanguage === Note.MARKUP_LANGUAGE_HTML ? 'text' : 'markdown'}
theme={styles.editor.editorTheme}
onFocus={onFocus}
onBlur={onBlur}
style={styles.editor}
width={`${width}px`}
fontSize={styles.editor.fontSize}
showGutter={false}
readOnly={props.visiblePanes.indexOf('editor') < 0}
readOnly={editorReadOnly}
name="note-editor"
wrapEnabled={true}
onScroll={editor_scroll}
Expand Down Expand Up @@ -654,7 +651,7 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) {
<Toolbar
theme={props.theme}
dispatch={props.dispatch}
disabled={!focused}
disabled={editorReadOnly}
/>
{props.noteToolbar}
</div>
Expand Down
15 changes: 0 additions & 15 deletions ElectronClient/gui/NoteEditor/NoteBody/AceEditor/utils/useFocus.ts

This file was deleted.

0 comments on commit f4092c0

Please sign in to comment.