Skip to content

Commit f7a6489

Browse files
AWolf81Rokt33r
authored andcommitted
fix auto-scroll
1 parent 6ec687e commit f7a6489

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

browser/main/NoteList/index.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class NoteList extends React.Component {
151151
const { selectedNoteKeys } = this.state
152152
const visibleNoteKeys = this.notes && this.notes.map(note => note.key)
153153
const note = this.notes && this.notes[0]
154+
const key = location.search && queryString.parse(location.search).key
154155
const prevKey = prevProps.location.search && queryString.parse(prevProps.location.search).key
155156
const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && note.key
156157

@@ -173,25 +174,25 @@ class NoteList extends React.Component {
173174
return
174175
}
175176

176-
// Auto scroll //<<<<<<<<<<<<<< fix me later
177-
// if (_.isString(location.query.key) && prevProps.location.query.key === location.query.key) {
178-
// const targetIndex = this.getTargetIndex()
179-
// if (targetIndex > -1) {
180-
// const list = this.refs.list
181-
// const item = list.childNodes[targetIndex]
182-
183-
// if (item == null) return false
184-
185-
// const overflowBelow = item.offsetTop + item.clientHeight - list.clientHeight - list.scrollTop > 0
186-
// if (overflowBelow) {
187-
// list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight
188-
// }
189-
// const overflowAbove = list.scrollTop > item.offsetTop
190-
// if (overflowAbove) {
191-
// list.scrollTop = item.offsetTop
192-
// }
193-
// }
194-
// }
177+
// Auto scroll
178+
if (_.isString(key) && prevKey === key) {
179+
const targetIndex = this.getTargetIndex()
180+
if (targetIndex > -1) {
181+
const list = this.refs.list
182+
const item = list.childNodes[targetIndex]
183+
184+
if (item == null) return false
185+
186+
const overflowBelow = item.offsetTop + item.clientHeight - list.clientHeight - list.scrollTop > 0
187+
if (overflowBelow) {
188+
list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight
189+
}
190+
const overflowAbove = list.scrollTop > item.offsetTop
191+
if (overflowAbove) {
192+
list.scrollTop = item.offsetTop
193+
}
194+
}
195+
}
195196
}
196197

197198
focusNote (selectedNoteKeys, noteKey, pathname) {

0 commit comments

Comments
 (0)