From 09df3156399048ad1ec55c5f0f45076df1a3c25c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 7 Sep 2019 11:57:31 +0100 Subject: [PATCH] Desktop: Fixes #1833: Do not scroll text when search is open and user type in note --- ElectronClient/app/gui/NoteText.jsx | 3 +++ ElectronClient/app/gui/note-viewer/index.html | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 12fff5553..eb1153507 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -270,6 +270,7 @@ class NoteTextComponent extends React.Component { localSearch: { query: query, selectedIndex: 0, + timestamp: Date.now(), }, }); }; @@ -277,6 +278,7 @@ class NoteTextComponent extends React.Component { const noteSearchBarNextPrevious = inc => { const ls = Object.assign({}, this.state.localSearch); ls.selectedIndex += inc; + ls.timestamp = Date.now(); if (ls.selectedIndex < 0) ls.selectedIndex = ls.resultCount - 1; if (ls.selectedIndex >= ls.resultCount) ls.selectedIndex = 0; @@ -1934,6 +1936,7 @@ class NoteTextComponent extends React.Component { ]; markerOptions.selectedIndex = this.state.localSearch.selectedIndex; markerOptions.separateWordSearch = false; + markerOptions.searchTimestamp = this.state.localSearch.timestamp; } else { const search = BaseModel.byId(this.props.searches, this.props.selectedSearchId); if (search) { diff --git a/ElectronClient/app/gui/note-viewer/index.html b/ElectronClient/app/gui/note-viewer/index.html index af4493a14..7624fd862 100644 --- a/ElectronClient/app/gui/note-viewer/index.html +++ b/ElectronClient/app/gui/note-viewer/index.html @@ -227,7 +227,11 @@ ipcProxySendToHost('setMarkerCount', elementIndex); - if (selectedElement) selectedElement.scrollIntoView(); + // We only scroll the element into view if the search just happened. So when the user type the search + // or select the next/previous result, we scroll into view. However for other actions that trigger a + // re-render, we don't scroll as this is normally not wanted. + // This is to go around this issue: https://github.com/laurent22/joplin/issues/1833 + if (selectedElement && Date.now() - options.searchTimestamp <= 1000) selectedElement.scrollIntoView(); } let markLoaded_ = false;