keybindings tweaks & fixes

This commit is contained in:
Nazar Kanaev 2021-03-03 12:29:32 +00:00
parent 57efbe4ebc
commit 5ec89f4041

View File

@ -1,46 +1,78 @@
function scrollto(target, scroll) {
var padding = 10
var targetRect = target.getBoundingClientRect()
var scrollRect = scroll.getBoundingClientRect()
// target
var relativeOffset = targetRect.y - scrollRect.y
var absoluteOffset = relativeOffset + scroll.scrollTop
if (padding <= relativeOffset && relativeOffset + targetRect.height <= scrollRect.height - padding) return
var newPos = scroll.scrollTop
if (relativeOffset < padding) {
newPos = absoluteOffset - padding
} else {
newPos = absoluteOffset - scrollRect.height + targetRect.height + padding
}
scroll.scrollTop = Math.round(newPos)
}
const helperFunctions = { const helperFunctions = {
// navigation helper, navigate relative to selected item // navigation helper, navigate relative to selected item
navigateToItem: function(relativePosition) { navigateToItem: function(relativePosition) {
if(vm.itemSelected == null){ if (vm.itemSelected == null) {
if(vm.items.length !== 0) { // if no item is selected, select first
// if no item is selected, select first if (vm.items.length !== 0) vm.itemSelected = vm.items[0].id
vm.itemSelected = vm.items[0].id
}
return return
} }
const itemPosition = vm.items.findIndex(x=>x.id==vm.itemSelected)
if(itemPosition == -1){ var itemPosition = vm.items.findIndex(function(x) { return x.id === vm.itemSelected })
// Item not found error if (itemPosition === -1) {
return if (vm.items.length !== 0) vm.itemSelected = vm.items[0].id
}
const newPosition = itemPosition+relativePosition
if(newPosition < 0 || newPosition >= vm.items.length){
return return
} }
var newPosition = itemPosition + relativePosition
if (newPosition < 0 || newPosition >= vm.items.length) return
vm.itemSelected = vm.items[newPosition].id vm.itemSelected = vm.items[newPosition].id
vm.$nextTick(function() {
var scroll = document.querySelector('#item-list-scroll')
var handle = scroll.querySelector('input[type=radio]:checked')
var target = handle && handle.parentElement
if (target && scroll) scrollto(target, scroll)
})
}, },
// navigation helper, navigate relative to selected feed // navigation helper, navigate relative to selected feed
navigateToFeed: function(relativePosition) { navigateToFeed: function(relativePosition) {
// create a list with feed and folders guids, ignore feeds in collapsed folders var navigationList = Array.from(document.querySelectorAll('#col-feed-list input[name=feed]'))
// Example result with folder 2 collapsed: .filter(function(r) { return r.offsetParent !== null && r.value !== 'folder:null' })
// ['','folder:1','feed:1','feed:2','folder:2', 'folder:3','feed:3'] .map(function(r) { return r.value })
// The empty string is the "All Feeds" option
const navigationList = [''].concat(vm.foldersWithFeeds.map( var currentFeedPosition = navigationList.indexOf(vm.feedSelected)
folder =>
folder.is_expanded if (currentFeedPosition == -1) {
? ['folder:'+folder.id].concat(folder.feeds.map(feed=>'feed:'+feed.id)) vm.feedSelected = ''
: 'folder:'+folder.id
).flat())
const currentFeedPosition = navigationList.indexOf(vm.feedSelected)
if(currentFeedPosition== -1){
// feed not found error
return return
} }
const newPosition = currentFeedPosition+relativePosition
if(newPosition < 0 || newPosition >= navigationList.length){ var newPosition = currentFeedPosition+relativePosition
return if (newPosition < 0 || newPosition >= navigationList.length) return
}
vm.feedSelected = navigationList[newPosition]; vm.feedSelected = navigationList[newPosition]
vm.$nextTick(function() {
var scroll = document.querySelector('#feed-list-scroll')
var handle = scroll.querySelector('input[type=radio]:checked')
var target = handle && handle.parentElement
if (target && scroll) scrollto(target, scroll)
})
} }
} }
const shortcutFunctions = { const shortcutFunctions = {
@ -91,14 +123,14 @@ const keybindings = {
"r": shortcutFunctions.toggleItemRead, "r": shortcutFunctions.toggleItemRead,
"R": shortcutFunctions.markAllRead, "R": shortcutFunctions.markAllRead,
"s": shortcutFunctions.toggleItemStarred, "s": shortcutFunctions.toggleItemStarred,
"?": shortcutFunctions.focusSearch, "/": shortcutFunctions.focusSearch,
"j": shortcutFunctions.nextItem, "j": shortcutFunctions.nextItem,
"k": shortcutFunctions.previousItem, "k": shortcutFunctions.previousItem,
"l": shortcutFunctions.nextFeed, "l": shortcutFunctions.nextFeed,
"h": shortcutFunctions.previousFeed, "h": shortcutFunctions.previousFeed,
"A": shortcutFunctions.showAll, "1": shortcutFunctions.showUnread,
"U": shortcutFunctions.showUnread, "2": shortcutFunctions.showStarred,
"S": shortcutFunctions.showStarred, "3": shortcutFunctions.showAll,
} }
function isTextBox(element) { function isTextBox(element) {