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 * as focusElementNoteList from './commands/focusElementNoteList';
|
||||||
import CommandService from '@joplin/lib/services/CommandService';
|
import CommandService from '@joplin/lib/services/CommandService';
|
||||||
import useDragAndDrop from './utils/useDragAndDrop';
|
import useDragAndDrop from './utils/useDragAndDrop';
|
||||||
import usePrevious from '../hooks/usePrevious';
|
|
||||||
import { itemIsInTrash } from '@joplin/lib/services/trash';
|
import { itemIsInTrash } from '@joplin/lib/services/trash';
|
||||||
import Folder from '@joplin/lib/models/Folder';
|
import Folder from '@joplin/lib/models/Folder';
|
||||||
import { focus } from '@joplin/lib/utils/focusHandler';
|
|
||||||
const { connect } = require('react-redux');
|
const { connect } = require('react-redux');
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
@ -146,29 +144,38 @@ const NoteList = (props: Props) => {
|
|||||||
props.selectedFolderInTrash,
|
props.selectedFolderInTrash,
|
||||||
);
|
);
|
||||||
|
|
||||||
const previousSelectedNoteIds = usePrevious(props.selectedNoteIds, []);
|
// 2024-04-01: Whatever the below effect is supposed to be doing has been lost in time and even
|
||||||
const previousNoteCount = usePrevious(props.notes.length, 0);
|
// if it's doing something useful it should be refactored. In my tests, removing it doesn't
|
||||||
const previousVisible = usePrevious(props.visible, false);
|
// 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(() => {
|
// const previousSelectedNoteIds = usePrevious(props.selectedNoteIds, []);
|
||||||
if (previousSelectedNoteIds !== props.selectedNoteIds && props.selectedNoteIds.length === 1) {
|
// const previousNoteCount = usePrevious(props.notes.length, 0);
|
||||||
const id = props.selectedNoteIds[0];
|
// const previousVisible = usePrevious(props.visible, false);
|
||||||
const doRefocus = props.notes.length < previousNoteCount && !props.focusedField;
|
|
||||||
|
|
||||||
for (let i = 0; i < props.notes.length; i++) {
|
// useEffect(() => {
|
||||||
if (props.notes[i].id === id) {
|
// if (previousSelectedNoteIds !== props.selectedNoteIds && props.selectedNoteIds.length === 1) {
|
||||||
makeItemIndexVisible(i);
|
// const id = props.selectedNoteIds[0];
|
||||||
if (doRefocus) {
|
// const doRefocus = props.notes.length < previousNoteCount && !props.focusedField;
|
||||||
const ref = itemRefs.current[id];
|
|
||||||
if (ref) {
|
// for (let i = 0; i < props.notes.length; i++) {
|
||||||
focus('NoteList::doRefocus', ref);
|
// if (props.notes[i].id === id) {
|
||||||
}
|
// makeItemIndexVisible(i);
|
||||||
}
|
// if (doRefocus) {
|
||||||
break;
|
// const ref = itemRefs.current[id];
|
||||||
}
|
// if (ref) {
|
||||||
}
|
// focus('NoteList::doRefocus', ref);
|
||||||
}
|
// }
|
||||||
}, [makeItemIndexVisible, previousSelectedNoteIds, previousNoteCount, previousVisible, props.selectedNoteIds, props.notes, props.focusedField, props.visible]);
|
// }
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }, [makeItemIndexVisible, previousSelectedNoteIds, previousNoteCount, previousVisible, props.selectedNoteIds, props.notes, props.focusedField, props.visible]);
|
||||||
|
|
||||||
const highlightedWords = useMemo(() => {
|
const highlightedWords = useMemo(() => {
|
||||||
if (props.notesParentType === 'Search') {
|
if (props.notesParentType === 'Search') {
|
||||||
|
Loading…
Reference in New Issue
Block a user