mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixes #10108: When creating a note or to-do, focus is not set correctly
This commit is contained in:
parent
b622f9b938
commit
f60e105d77
@ -21,10 +21,8 @@ import useOnKeyDown from './utils/useOnKeyDown';
|
||||
import * as focusElementNoteList from './commands/focusElementNoteList';
|
||||
import CommandService from '@joplin/lib/services/CommandService';
|
||||
import useDragAndDrop from './utils/useDragAndDrop';
|
||||
import usePrevious from '../hooks/usePrevious';
|
||||
import { itemIsInTrash } from '@joplin/lib/services/trash';
|
||||
import Folder from '@joplin/lib/models/Folder';
|
||||
import { focus } from '@joplin/lib/utils/focusHandler';
|
||||
const { connect } = require('react-redux');
|
||||
|
||||
const commands = {
|
||||
@ -146,29 +144,38 @@ const NoteList = (props: Props) => {
|
||||
props.selectedFolderInTrash,
|
||||
);
|
||||
|
||||
const previousSelectedNoteIds = usePrevious(props.selectedNoteIds, []);
|
||||
const previousNoteCount = usePrevious(props.notes.length, 0);
|
||||
const previousVisible = usePrevious(props.visible, false);
|
||||
// 2024-04-01: Whatever the below effect is supposed to be doing has been lost in time and even
|
||||
// if it's doing something useful it should be refactored. In my tests, removing it doesn't
|
||||
// affect anything - including scrolling with the keyboard and switching notes so there's a
|
||||
// chance that whatever it's doing is being done more cleanly somewhere else. If a focus
|
||||
// related-bug is found, it should be fixed from scratch, without touching this event, although
|
||||
// it could possibly be used as a reference.
|
||||
//
|
||||
// * * *
|
||||
|
||||
useEffect(() => {
|
||||
if (previousSelectedNoteIds !== props.selectedNoteIds && props.selectedNoteIds.length === 1) {
|
||||
const id = props.selectedNoteIds[0];
|
||||
const doRefocus = props.notes.length < previousNoteCount && !props.focusedField;
|
||||
// const previousSelectedNoteIds = usePrevious(props.selectedNoteIds, []);
|
||||
// const previousNoteCount = usePrevious(props.notes.length, 0);
|
||||
// const previousVisible = usePrevious(props.visible, false);
|
||||
|
||||
for (let i = 0; i < props.notes.length; i++) {
|
||||
if (props.notes[i].id === id) {
|
||||
makeItemIndexVisible(i);
|
||||
if (doRefocus) {
|
||||
const ref = itemRefs.current[id];
|
||||
if (ref) {
|
||||
focus('NoteList::doRefocus', ref);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [makeItemIndexVisible, previousSelectedNoteIds, previousNoteCount, previousVisible, props.selectedNoteIds, props.notes, props.focusedField, props.visible]);
|
||||
// useEffect(() => {
|
||||
// if (previousSelectedNoteIds !== props.selectedNoteIds && props.selectedNoteIds.length === 1) {
|
||||
// const id = props.selectedNoteIds[0];
|
||||
// const doRefocus = props.notes.length < previousNoteCount && !props.focusedField;
|
||||
|
||||
// for (let i = 0; i < props.notes.length; i++) {
|
||||
// if (props.notes[i].id === id) {
|
||||
// makeItemIndexVisible(i);
|
||||
// if (doRefocus) {
|
||||
// const ref = itemRefs.current[id];
|
||||
// if (ref) {
|
||||
// focus('NoteList::doRefocus', ref);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }, [makeItemIndexVisible, previousSelectedNoteIds, previousNoteCount, previousVisible, props.selectedNoteIds, props.notes, props.focusedField, props.visible]);
|
||||
|
||||
const highlightedWords = useMemo(() => {
|
||||
if (props.notesParentType === 'Search') {
|
||||
|
Loading…
Reference in New Issue
Block a user