tweak Headlines.click: ctrl-click toggles selection, shift-click selects range

This commit is contained in:
Andrew Dolgov 2019-03-07 10:35:48 +03:00
parent 3906b27781
commit d876cca22a
1 changed files with 47 additions and 20 deletions

View File

@ -153,35 +153,38 @@ define(["dojo/_base/declare"], function (declare) {
click: function (event, id, in_body) { click: function (event, id, in_body) {
in_body = in_body || false; in_body = in_body || false;
if (App.isCombinedMode()) { if (event.shiftKey && Article.getActive()) {
Headlines.select('none');
if (!in_body && (event.ctrlKey || id == Article.getActive() || App.getInitParam("cdm_expanded"))) { const ids = Headlines.getRange(Article.getActive(), id);
Article.openInNewWindow(id);
Headlines.toggleUnread(id, 0);
return false;
}
if (Article.getActive() != id) { console.log(Article.getActive(), id, ids);
Article.setActive(id);
if (!App.getInitParam("cdm_expanded")) for (let i = 0; i < ids.length; i++)
Article.cdmScrollToId(id); Headlines.select('all', ids[i]);
} else if (in_body) {
Headlines.toggleUnread(id, 0);
}
return in_body;
} else if (event.ctrlKey) {
Headlines.select('invert', id);
} else { } else {
if (event.ctrlKey) { if (App.isCombinedMode()) {
Article.openInNewWindow(id);
Headlines.toggleUnread(id, 0); if (Article.getActive() != id) {
Article.setActive(id);
if (!App.getInitParam("cdm_expanded"))
Article.cdmScrollToId(id);
} else if (in_body) {
Headlines.toggleUnread(id, 0);
}
return in_body;
} else { } else {
Article.view(id); Article.view(id);
} }
return false;
} }
return false;
}, },
initScrollHandler: function () { initScrollHandler: function () {
$("headlines-frame").onscroll = (event) => { $("headlines-frame").onscroll = (event) => {
@ -997,6 +1000,30 @@ define(["dojo/_base/declare"], function (declare) {
row.removeClassName("Selected"); row.removeClassName("Selected");
} }
}, },
getRange: function (start, stop) {
const rows = $$("#headlines-frame > div[id*=RROW]");
const results = [];
let collecting = false;
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const id = row.getAttribute('data-article-id');
if (id == start || id == stop) {
if (!collecting) {
collecting = true;
} else {
results.push(id);
break;
}
}
if (collecting)
results.push(id);
}
return results;
},
select: function (mode, articleId) { select: function (mode, articleId) {
// mode = all,none,unread,invert,marked,published // mode = all,none,unread,invert,marked,published
let query = "#headlines-frame > div[id*=RROW]"; let query = "#headlines-frame > div[id*=RROW]";