add hotkeys J/K to move between unread feeds
This commit is contained in:
parent
4795c4a2a9
commit
8574532b7f
|
@ -564,7 +564,9 @@ class RPC extends Handler_Protected {
|
||||||
$hotkeys = array(
|
$hotkeys = array(
|
||||||
__("Navigation") => array(
|
__("Navigation") => array(
|
||||||
"next_feed" => __("Open next feed"),
|
"next_feed" => __("Open next feed"),
|
||||||
|
"next_unread_feed" => __("Open next unread feed"),
|
||||||
"prev_feed" => __("Open previous feed"),
|
"prev_feed" => __("Open previous feed"),
|
||||||
|
"prev_unread_feed" => __("Open previous unread feed"),
|
||||||
"next_article_or_scroll" => __("Open next article (in combined mode, scroll down)"),
|
"next_article_or_scroll" => __("Open next article (in combined mode, scroll down)"),
|
||||||
"prev_article_or_scroll" => __("Open previous article (in combined mode, scroll up)"),
|
"prev_article_or_scroll" => __("Open previous article (in combined mode, scroll up)"),
|
||||||
"next_headlines_page" => __("Scroll headlines by one page down"),
|
"next_headlines_page" => __("Scroll headlines by one page down"),
|
||||||
|
@ -643,7 +645,9 @@ class RPC extends Handler_Protected {
|
||||||
static function get_hotkeys_map() {
|
static function get_hotkeys_map() {
|
||||||
$hotkeys = array(
|
$hotkeys = array(
|
||||||
"k" => "next_feed",
|
"k" => "next_feed",
|
||||||
|
"K" => "next_unread_feed",
|
||||||
"j" => "prev_feed",
|
"j" => "prev_feed",
|
||||||
|
"J" => "prev_unread_feed",
|
||||||
"n" => "next_article_noscroll",
|
"n" => "next_article_noscroll",
|
||||||
"p" => "prev_article_noscroll",
|
"p" => "prev_article_noscroll",
|
||||||
"N" => "article_page_down",
|
"N" => "article_page_down",
|
||||||
|
|
14
js/App.js
14
js/App.js
|
@ -944,6 +944,13 @@ const App = {
|
||||||
if (feed !== false)
|
if (feed !== false)
|
||||||
Feeds.open({feed: feed, is_cat: is_cat, delayed: true})
|
Feeds.open({feed: feed, is_cat: is_cat, delayed: true})
|
||||||
};
|
};
|
||||||
|
this.hotkey_actions["next_unread_feed"] = () => {
|
||||||
|
const [feed, is_cat] = Feeds.getNextFeed(
|
||||||
|
Feeds.getActive(), Feeds.activeIsCat(), true);
|
||||||
|
|
||||||
|
if (feed !== false)
|
||||||
|
Feeds.open({feed: feed, is_cat: is_cat, delayed: true})
|
||||||
|
};
|
||||||
this.hotkey_actions["prev_feed"] = () => {
|
this.hotkey_actions["prev_feed"] = () => {
|
||||||
const [feed, is_cat] = Feeds.getPreviousFeed(
|
const [feed, is_cat] = Feeds.getPreviousFeed(
|
||||||
Feeds.getActive(), Feeds.activeIsCat());
|
Feeds.getActive(), Feeds.activeIsCat());
|
||||||
|
@ -951,6 +958,13 @@ const App = {
|
||||||
if (feed !== false)
|
if (feed !== false)
|
||||||
Feeds.open({feed: feed, is_cat: is_cat, delayed: true})
|
Feeds.open({feed: feed, is_cat: is_cat, delayed: true})
|
||||||
};
|
};
|
||||||
|
this.hotkey_actions["prev_unread_feed"] = () => {
|
||||||
|
const [feed, is_cat] = Feeds.getPreviousFeed(
|
||||||
|
Feeds.getActive(), Feeds.activeIsCat(), true);
|
||||||
|
|
||||||
|
if (feed !== false)
|
||||||
|
Feeds.open({feed: feed, is_cat: is_cat, delayed: true})
|
||||||
|
};
|
||||||
this.hotkey_actions["next_article_or_scroll"] = (event) => {
|
this.hotkey_actions["next_article_or_scroll"] = (event) => {
|
||||||
if (this.isCombinedMode())
|
if (this.isCombinedMode())
|
||||||
Headlines.scroll(Headlines.line_scroll_offset, event);
|
Headlines.scroll(Headlines.line_scroll_offset, event);
|
||||||
|
|
|
@ -434,14 +434,15 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
|
|
||||||
return [false, false];
|
return [false, false];
|
||||||
},
|
},
|
||||||
_prevTreeItemFromIndex: function (start) {
|
_prevTreeItemFromIndex: function (start, unread_only) {
|
||||||
const items = this.model.store._arrayOfAllItems;
|
const items = this.model.store._arrayOfAllItems;
|
||||||
|
|
||||||
for (let i = start-1; i > 0; i--) {
|
for (let i = start-1; i > 0; i--) {
|
||||||
const id = String(items[i].id);
|
const id = String(items[i].id);
|
||||||
const box = this._itemNodesMap[id];
|
const box = this._itemNodesMap[id];
|
||||||
|
const unread = parseInt(items[i].unread);
|
||||||
|
|
||||||
if (box) {
|
if (box && (!unread_only || unread > 0)) {
|
||||||
const row = box[0].rowNode;
|
const row = box[0].rowNode;
|
||||||
const cat = box[0].rowNode.parentNode.parentNode;
|
const cat = box[0].rowNode.parentNode.parentNode;
|
||||||
|
|
||||||
|
@ -451,7 +452,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getPreviousFeed: function (feed, is_cat) {
|
getPreviousFeed: function (feed, is_cat, unread_only = false) {
|
||||||
let treeItem;
|
let treeItem;
|
||||||
|
|
||||||
if (is_cat) {
|
if (is_cat) {
|
||||||
|
@ -464,11 +465,11 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
const start = items.indexOf(treeItem);
|
const start = items.indexOf(treeItem);
|
||||||
|
|
||||||
if (start != -1) {
|
if (start != -1) {
|
||||||
let item = this._prevTreeItemFromIndex(start);
|
let item = this._prevTreeItemFromIndex(start, unread_only);
|
||||||
|
|
||||||
// wrap from the bottom
|
// wrap from the bottom
|
||||||
if (!item) {
|
if (!item) {
|
||||||
item = this._prevTreeItemFromIndex(items.length);
|
item = this._prevTreeItemFromIndex(items.length, unread_only);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item)
|
if (item)
|
||||||
|
|
|
@ -583,17 +583,17 @@ const Feeds = {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
getNextFeed: function(feed, is_cat) {
|
getNextFeed: function(feed, is_cat, unread_only = false) {
|
||||||
const tree = dijit.byId("feedTree");
|
const tree = dijit.byId("feedTree");
|
||||||
|
|
||||||
if (tree) return tree.getNextFeed(feed, is_cat, false);
|
if (tree) return tree.getNextFeed(feed, is_cat, unread_only);
|
||||||
|
|
||||||
return [false, false];
|
return [false, false];
|
||||||
},
|
},
|
||||||
getPreviousFeed: function(feed, is_cat) {
|
getPreviousFeed: function(feed, is_cat, unread_only = false) {
|
||||||
const tree = dijit.byId("feedTree");
|
const tree = dijit.byId("feedTree");
|
||||||
|
|
||||||
if (tree) return tree.getPreviousFeed(feed, is_cat);
|
if (tree) return tree.getPreviousFeed(feed, is_cat, unread_only);
|
||||||
|
|
||||||
return [false, false];
|
return [false, false];
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,7 +18,9 @@ class Hotkeys_Swap_JK extends Plugin {
|
||||||
function hook_hotkey_map($hotkeys) {
|
function hook_hotkey_map($hotkeys) {
|
||||||
|
|
||||||
$hotkeys["j"] = "next_feed";
|
$hotkeys["j"] = "next_feed";
|
||||||
|
$hotkeys["J"] = "next_unread_feed";
|
||||||
$hotkeys["k"] = "prev_feed";
|
$hotkeys["k"] = "prev_feed";
|
||||||
|
$hotkeys["K"] = "prev_unread_feed";
|
||||||
|
|
||||||
return $hotkeys;
|
return $hotkeys;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue