mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
parent
9d96866531
commit
b4ca00ebf5
@ -6,8 +6,8 @@ import { defaultSearchState, SearchPanel } from './SearchPanel';
|
|||||||
import ExtendedWebView from '../ExtendedWebView';
|
import ExtendedWebView from '../ExtendedWebView';
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { forwardRef, RefObject, useImperativeHandle } from 'react';
|
import { forwardRef, useImperativeHandle } from 'react';
|
||||||
import { useEffect, useMemo, useState, useCallback, useRef } from 'react';
|
import { useMemo, useState, useCallback, useRef } from 'react';
|
||||||
import { LayoutChangeEvent, View, ViewStyle } from 'react-native';
|
import { LayoutChangeEvent, View, ViewStyle } from 'react-native';
|
||||||
const { editorFont } = require('../global-style');
|
const { editorFont } = require('../global-style');
|
||||||
|
|
||||||
@ -126,7 +126,6 @@ type OnSearchStateChangeCallback = (state: SearchState)=> void;
|
|||||||
const useEditorControl = (
|
const useEditorControl = (
|
||||||
injectJS: OnInjectJSCallback, setLinkDialogVisible: OnSetVisibleCallback,
|
injectJS: OnInjectJSCallback, setLinkDialogVisible: OnSetVisibleCallback,
|
||||||
setSearchState: OnSearchStateChangeCallback,
|
setSearchState: OnSearchStateChangeCallback,
|
||||||
searchStateRef: RefObject<SearchState>,
|
|
||||||
): EditorControl => {
|
): EditorControl => {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const execCommand = (command: EditorCommandType) => {
|
const execCommand = (command: EditorCommandType) => {
|
||||||
@ -252,16 +251,10 @@ const useEditorControl = (
|
|||||||
},
|
},
|
||||||
|
|
||||||
showSearch() {
|
showSearch() {
|
||||||
setSearchState({
|
execCommand(EditorCommandType.ShowSearch);
|
||||||
...searchStateRef.current,
|
|
||||||
dialogVisible: true,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
hideSearch() {
|
hideSearch() {
|
||||||
setSearchState({
|
execCommand(EditorCommandType.HideSearch);
|
||||||
...searchStateRef.current,
|
|
||||||
dialogVisible: false,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setSearchState: setSearchStateCallback,
|
setSearchState: setSearchStateCallback,
|
||||||
@ -269,7 +262,7 @@ const useEditorControl = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
return control;
|
return control;
|
||||||
}, [injectJS, searchStateRef, setLinkDialogVisible, setSearchState]);
|
}, [injectJS, setLinkDialogVisible, setSearchState]);
|
||||||
};
|
};
|
||||||
|
|
||||||
function NoteEditor(props: Props, ref: any) {
|
function NoteEditor(props: Props, ref: any) {
|
||||||
@ -356,22 +349,13 @@ function NoteEditor(props: Props, ref: any) {
|
|||||||
const [linkDialogVisible, setLinkDialogVisible] = useState(false);
|
const [linkDialogVisible, setLinkDialogVisible] = useState(false);
|
||||||
const [searchState, setSearchState] = useState(defaultSearchState);
|
const [searchState, setSearchState] = useState(defaultSearchState);
|
||||||
|
|
||||||
// Having a [searchStateRef] allows [editorControl] to not be re-created
|
|
||||||
// whenever [searchState] changes.
|
|
||||||
const searchStateRef = useRef(defaultSearchState);
|
|
||||||
|
|
||||||
// Keep the reference and the [searchState] in sync
|
|
||||||
useEffect(() => {
|
|
||||||
searchStateRef.current = searchState;
|
|
||||||
}, [searchState]);
|
|
||||||
|
|
||||||
// Runs [js] in the context of the CodeMirror frame.
|
// Runs [js] in the context of the CodeMirror frame.
|
||||||
const injectJS = (js: string) => {
|
const injectJS = (js: string) => {
|
||||||
webviewRef.current.injectJS(js);
|
webviewRef.current.injectJS(js);
|
||||||
};
|
};
|
||||||
|
|
||||||
const editorControl = useEditorControl(
|
const editorControl = useEditorControl(
|
||||||
injectJS, setLinkDialogVisible, setSearchState, searchStateRef,
|
injectJS, setLinkDialogVisible, setSearchState,
|
||||||
);
|
);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => {
|
useImperativeHandle(ref, () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user