From f7a648903e1eb47bd2516e3305b9858e3035aa4e Mon Sep 17 00:00:00 2001 From: AWolf81 Date: Sat, 4 May 2019 01:36:06 +0200 Subject: [PATCH] fix auto-scroll --- browser/main/NoteList/index.js | 35 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index f4002ae3..16b4ea88 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -151,6 +151,7 @@ class NoteList extends React.Component { const { selectedNoteKeys } = this.state const visibleNoteKeys = this.notes && this.notes.map(note => note.key) const note = this.notes && this.notes[0] + const key = location.search && queryString.parse(location.search).key const prevKey = prevProps.location.search && queryString.parse(prevProps.location.search).key const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && note.key @@ -173,25 +174,25 @@ class NoteList extends React.Component { return } - // Auto scroll //<<<<<<<<<<<<<< fix me later - // if (_.isString(location.query.key) && prevProps.location.query.key === location.query.key) { - // const targetIndex = this.getTargetIndex() - // if (targetIndex > -1) { - // const list = this.refs.list - // const item = list.childNodes[targetIndex] + // Auto scroll + if (_.isString(key) && prevKey === key) { + const targetIndex = this.getTargetIndex() + if (targetIndex > -1) { + const list = this.refs.list + const item = list.childNodes[targetIndex] - // if (item == null) return false + if (item == null) return false - // const overflowBelow = item.offsetTop + item.clientHeight - list.clientHeight - list.scrollTop > 0 - // if (overflowBelow) { - // list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight - // } - // const overflowAbove = list.scrollTop > item.offsetTop - // if (overflowAbove) { - // list.scrollTop = item.offsetTop - // } - // } - // } + const overflowBelow = item.offsetTop + item.clientHeight - list.clientHeight - list.scrollTop > 0 + if (overflowBelow) { + list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight + } + const overflowAbove = list.scrollTop > item.offsetTop + if (overflowAbove) { + list.scrollTop = item.offsetTop + } + } + } } focusNote (selectedNoteKeys, noteKey, pathname) {