From ca4dfe0f0f128651fb085a57bc8b6d32d6ae7e5c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 13 Jul 2019 17:40:09 +0100 Subject: [PATCH] Desktop: Fixes #1724: Improved note selection and scrolling when moving a note to a different notebook --- ElectronClient/app/gui/ItemList.jsx | 2 +- ReactNativeClient/lib/reducer.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ElectronClient/app/gui/ItemList.jsx b/ElectronClient/app/gui/ItemList.jsx index 55cb2bc9c..686d3760b 100644 --- a/ElectronClient/app/gui/ItemList.jsx +++ b/ElectronClient/app/gui/ItemList.jsx @@ -52,7 +52,7 @@ class ItemList extends React.Component { makeItemIndexVisible(itemIndex) { const top = Math.min(this.props.items.length - 1, this.state.topItemIndex + 1); - const bottom = Math.max(0, this.state.bottomItemIndex - 1) + const bottom = Math.max(0, this.state.bottomItemIndex) if (itemIndex >= top && itemIndex <= bottom) return; diff --git a/ReactNativeClient/lib/reducer.js b/ReactNativeClient/lib/reducer.js index 696357446..981667384 100644 --- a/ReactNativeClient/lib/reducer.js +++ b/ReactNativeClient/lib/reducer.js @@ -406,6 +406,7 @@ const reducer = (state = defaultState, action) => { return false; } + let movedNotePreviousIndex = 0; let noteFolderHasChanged = false; let newNotes = state.notes.slice(); var found = false; @@ -427,6 +428,7 @@ const reducer = (state = defaultState, action) => { } else { // Note has moved to a different folder newNotes.splice(i, 1); noteFolderHasChanged = true; + movedNotePreviousIndex = i; } found = true; break; @@ -447,7 +449,10 @@ const reducer = (state = defaultState, action) => { newState.notes = newNotes; if (noteFolderHasChanged) { - newState.selectedNoteIds = newNotes.length ? [newNotes[0].id] : []; + let newIndex = movedNotePreviousIndex; + if (newIndex >= newNotes.length) newIndex = newNotes.length - 1; + if (!newNotes.length) newIndex = -1; + newState.selectedNoteIds = newIndex >= 0 ? [newNotes[newIndex].id] : []; } break;