From f78118325080129057fedc31057455ad0f9794bb Mon Sep 17 00:00:00 2001 From: Mohamad Ashraf Date: Tue, 26 Mar 2024 13:45:15 +0200 Subject: [PATCH] Desktop: Fixes #10078: Fixed auto scrolling with moving a note (#10193) --- packages/app-desktop/gui/NoteList/NoteList2.tsx | 3 +++ .../gui/NoteList/utils/useMoveNote.ts | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/app-desktop/gui/NoteList/NoteList2.tsx b/packages/app-desktop/gui/NoteList/NoteList2.tsx index b0f10f82e..3c2cf634c 100644 --- a/packages/app-desktop/gui/NoteList/NoteList2.tsx +++ b/packages/app-desktop/gui/NoteList/NoteList2.tsx @@ -77,6 +77,9 @@ const NoteList = (props: Props) => { props.showCompletedTodos, props.notes, props.selectedFolderInTrash, + makeItemIndexVisible, + focusNote, + props.dispatch, ); const noteItemStyle = useMemo(() => { diff --git a/packages/app-desktop/gui/NoteList/utils/useMoveNote.ts b/packages/app-desktop/gui/NoteList/utils/useMoveNote.ts index b1ece9b1c..c31b37eb5 100644 --- a/packages/app-desktop/gui/NoteList/utils/useMoveNote.ts +++ b/packages/app-desktop/gui/NoteList/utils/useMoveNote.ts @@ -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; };