mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
This commit is contained in:
parent
854f1163cd
commit
5fb01b5c7a
@ -94,7 +94,7 @@ function NoteEditor(props: NoteEditorProps) {
|
|||||||
showLocalSearch,
|
showLocalSearch,
|
||||||
setShowLocalSearch,
|
setShowLocalSearch,
|
||||||
searchMarkers: localSearchMarkerOptions,
|
searchMarkers: localSearchMarkerOptions,
|
||||||
} = useNoteSearchBar();
|
} = useNoteSearchBar({ noteSearchBarRef });
|
||||||
|
|
||||||
// If the note has been modified in another editor, wait for it to be saved
|
// If the note has been modified in another editor, wait for it to be saved
|
||||||
// before loading it in this editor.
|
// before loading it in this editor.
|
||||||
|
@ -11,9 +11,12 @@ export const runtime = (comp: any): CommandRuntime => {
|
|||||||
execute: async () => {
|
execute: async () => {
|
||||||
if (comp.editorRef.current && comp.editorRef.current.supportsCommand('search')) {
|
if (comp.editorRef.current && comp.editorRef.current.supportsCommand('search')) {
|
||||||
comp.editorRef.current.execCommand({ name: 'search' });
|
comp.editorRef.current.execCommand({ name: 'search' });
|
||||||
|
} else {
|
||||||
|
if (comp.noteSearchBarRef.current) {
|
||||||
|
comp.noteSearchBarRef.current.focus();
|
||||||
} else {
|
} else {
|
||||||
comp.setShowLocalSearch(true);
|
comp.setShowLocalSearch(true);
|
||||||
if (comp.noteSearchBarRef.current) comp.noteSearchBarRef.current.wrappedInstance.focus();
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabledCondition: 'oneNoteSelected',
|
enabledCondition: 'oneNoteSelected',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useState, useCallback } from 'react';
|
import { useState, useCallback, MutableRefObject, useEffect } from 'react';
|
||||||
import Logger from '@joplin/lib/Logger';
|
import Logger from '@joplin/lib/Logger';
|
||||||
import { SearchMarkers } from './useSearchMarkers';
|
import { SearchMarkers } from './useSearchMarkers';
|
||||||
const CommandService = require('@joplin/lib/services/CommandService').default;
|
const CommandService = require('@joplin/lib/services/CommandService').default;
|
||||||
@ -25,10 +25,21 @@ function defaultLocalSearch(): LocalSearch {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useNoteSearchBar() {
|
export interface UseNoteSearchBarProps {
|
||||||
|
noteSearchBarRef: MutableRefObject<any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function useNoteSearchBar({ noteSearchBarRef }: UseNoteSearchBarProps) {
|
||||||
const [showLocalSearch, setShowLocalSearch] = useState(false);
|
const [showLocalSearch, setShowLocalSearch] = useState(false);
|
||||||
const [localSearch, setLocalSearch] = useState<LocalSearch>(defaultLocalSearch());
|
const [localSearch, setLocalSearch] = useState<LocalSearch>(defaultLocalSearch());
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (showLocalSearch && noteSearchBarRef.current) {
|
||||||
|
noteSearchBarRef.current.focus();
|
||||||
|
}
|
||||||
|
}, [showLocalSearch, noteSearchBarRef]);
|
||||||
|
|
||||||
const onChange = useCallback((query: string) => {
|
const onChange = useCallback((query: string) => {
|
||||||
// A query that's too long would make CodeMirror throw an exception
|
// A query that's too long would make CodeMirror throw an exception
|
||||||
// which would crash the app.
|
// which would crash the app.
|
||||||
|
@ -11,6 +11,7 @@ class NoteSearchBar extends React.Component {
|
|||||||
this.previousButton_click = this.previousButton_click.bind(this);
|
this.previousButton_click = this.previousButton_click.bind(this);
|
||||||
this.nextButton_click = this.nextButton_click.bind(this);
|
this.nextButton_click = this.nextButton_click.bind(this);
|
||||||
this.closeButton_click = this.closeButton_click.bind(this);
|
this.closeButton_click = this.closeButton_click.bind(this);
|
||||||
|
this.focus = this.focus.bind(this);
|
||||||
|
|
||||||
this.backgroundColor = undefined;
|
this.backgroundColor = undefined;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user