1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #10078: Fixed auto scrolling with moving a note (#10193)

This commit is contained in:
Mohamad Ashraf 2024-03-26 13:45:15 +02:00 committed by GitHub
parent c1ae449ce2
commit f781183250
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -77,6 +77,9 @@ const NoteList = (props: Props) => {
props.showCompletedTodos,
props.notes,
props.selectedFolderInTrash,
makeItemIndexVisible,
focusNote,
props.dispatch,
);
const noteItemStyle = useMemo(() => {

View File

@ -3,8 +3,10 @@ import Note from '@joplin/lib/models/Note';
import { NoteEntity } from '@joplin/lib/services/database/types';
import { useCallback } from 'react';
import canManuallySortNotes from './canManuallySortNotes';
import { FocusNote } from './useFocusNote';
import { Dispatch } from 'redux';
const useMoveNote = (notesParentType: string, noteSortOrder: string, selectedNoteIds: string[], selectedFolderId: string, uncompletedTodosOnTop: boolean, showCompletedTodos: boolean, notes: NoteEntity[], selectedFolderInTrash: boolean) => {
const useMoveNote = (notesParentType: string, noteSortOrder: string, selectedNoteIds: string[], selectedFolderId: string, uncompletedTodosOnTop: boolean, showCompletedTodos: boolean, notes: NoteEntity[], selectedFolderInTrash: boolean, makeItemIndexVisible: (itemIndex: number)=> void, focusNote: FocusNote, dispatch: Dispatch) => {
const moveNote = useCallback((direction: number, inc: number) => {
if (!canManuallySortNotes(notesParentType, noteSortOrder, selectedFolderInTrash)) return;
@ -17,7 +19,17 @@ const useMoveNote = (notesParentType: string, noteSortOrder: string, selectedNot
targetNoteIndex -= inc;
}
void Note.insertNotesAt(selectedFolderId, selectedNoteIds, targetNoteIndex, uncompletedTodosOnTop, showCompletedTodos);
}, [selectedFolderId, noteSortOrder, notes, notesParentType, selectedNoteIds, uncompletedTodosOnTop, showCompletedTodos, selectedFolderInTrash]);
// The note will be moved to the target index, so we need to update the scroll amount to make it visible
dispatch({
type: 'NOTE_SELECT',
id: noteId,
});
makeItemIndexVisible(targetNoteIndex);
focusNote(noteId);
}, [selectedFolderId, noteSortOrder, notes, notesParentType, selectedNoteIds, uncompletedTodosOnTop, showCompletedTodos, selectedFolderInTrash, makeItemIndexVisible, focusNote, dispatch]);
return moveNote;
};