Skip to content

Commit

Permalink
improve scroll snapping
Browse files Browse the repository at this point in the history
instead of "after-snapping", override the default wheel event
ref #7
  • Loading branch information
phil294 committed May 14, 2023
1 parent 84b042a commit d030697
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
44 changes: 15 additions & 29 deletions web/src/views/MainView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,36 +155,20 @@ export default
``###* @type {Ref<Commit[]>} ###
visible_commits = ref []
scroll_item_offset = 0
scroll_item_offset_end = 0
scroll_callback_debouncer = 0
scroll_callback_debouncer2 = 0
ignore_next_scroll_event = false
commits_scroller_updated = (###* @type number ### start_index, ###* @type number ### end_index) =>
if ignore_next_scroll_event
ignore_next_scroll_event = false
return
# https://github.com/Akryum/vue-virtual-scroller/issues/801
new_scroll_item_offset = if start_index > 0 then Math.max(3, start_index + 1) else 0
if new_scroll_item_offset != scroll_item_offset
scroll_item_offset = new_scroll_item_offset
scroll_item_offset_end = end_index
window.clearTimeout scroll_callback_debouncer
scroll_callback_debouncer = window.setTimeout scroll_callback, 80
scroll_callback = =>
visible_commits.value = filtered_commits.value.slice(scroll_item_offset, scroll_item_offset_end)
if not ignore_next_scroll_event
window.clearTimeout scroll_callback_debouncer2
scroll_callback_debouncer2 = window.setTimeout(=>
ignore_next_scroll_event = true
# We'll have to do it once again after a greater delay because
# somehow sometimes there's more scrolling going on *after* updated callback.
# This strategy seems to be reliable contrary to also listening to @scroll event.
scroll_callback()
, 500)
ignore_next_scroll_event = true
# Snap-scroll to the item - see link above. We do this so we don't show half rows
# so the connection fake commit always fits properly
commits_scroller_ref.value?.scrollToItem scroll_item_offset
scroll_item_offset = start_index + 2
visible_commits.value = filtered_commits.value.slice(scroll_item_offset, end_index)
scroller_on_wheel = (###* @type WheelEvent ### event) =>
event.preventDefault()
commits_scroller_ref.value?.scrollToItem scroll_item_offset + Math.round(event.deltaY / 20)
scroller_on_keydown = (###* @type KeyboardEvent ### event) =>
if event.key == 'ArrowDown'
event.preventDefault()
commits_scroller_ref.value?.scrollToItem scroll_item_offset + 1
else if event.key == 'ArrowUp'
event.preventDefault()
commits_scroller_ref.value?.scrollToItem scroll_item_offset - 1




Expand Down Expand Up @@ -317,4 +301,6 @@ export default
selected_git_action: store.selected_git_action
commit_context_menu_provider
git_status: store.git_status
scroller_on_wheel
scroller_on_keydown
}
2 changes: 1 addition & 1 deletion web/src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ref-tip :git_ref="branch_elem.branch"
#branches-connection
visualization.vis v-if="connection_fake_commit" :commit="connection_fake_commit" :vis_max_length="vis_max_length"
recycle-scroller#log.scroller.fill-w.flex-1 role="list" :items="filtered_commits" v-slot="{ item: commit }" key-field="i" size-field="scroll_height" :buffer="0" :emit-update="true" @update="commits_scroller_updated" ref="commits_scroller_ref" tabindex="-1" v-context-menu="commit_context_menu_provider"
recycle-scroller#log.scroller.fill-w.flex-1 role="list" :items="filtered_commits" v-slot="{ item: commit }" key-field="i" size-field="scroll_height" :buffer="0" :emit-update="true" @update="commits_scroller_updated" ref="commits_scroller_ref" tabindex="-1" v-context-menu="commit_context_menu_provider" @wheel="scroller_on_wheel" @keydown="scroller_on_keydown"
.row.commit :class="{selected_commit:selected_commits.includes(commit),empty:!commit.hash}" @click="commit_clicked(commit,$event)" role="button" :data-commit-hash="commit.hash"
visualization.vis :commit="commit" :vis_max_length="vis_max_length"
.info.flex-1.row.gap-20 v-if="commit.hash"
Expand Down

0 comments on commit d030697

Please sign in to comment.