Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/app-desktop/gui/NoteList/NoteList2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const NoteList = (props: Props) => {
props.showCompletedTodos,
props.notes,
props.selectedFolderInTrash,
makeItemIndexVisible,
focusNote,
props.dispatch,
);

const noteItemStyle = useMemo(() => {
Expand Down
16 changes: 14 additions & 2 deletions packages/app-desktop/gui/NoteList/utils/useMoveNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
};
Expand Down
Loading