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); console.log(Article.getActive(), id, ids);
return false;
} for (let i = 0; i < ids.length; i++)
Headlines.select('all', ids[i]);
} else if (event.ctrlKey) {
Headlines.select('invert', id);
} else {
if (App.isCombinedMode()) {
if (Article.getActive() != id) { if (Article.getActive() != id) {
Article.setActive(id); Article.setActive(id);
if (!App.getInitParam("cdm_expanded")) if (!App.getInitParam("cdm_expanded"))
Article.cdmScrollToId(id); Article.cdmScrollToId(id);
} else if (in_body) { } else if (in_body) {
Headlines.toggleUnread(id, 0); Headlines.toggleUnread(id, 0);
} }
return in_body; return in_body;
} else {
if (event.ctrlKey) {
Article.openInNewWindow(id);
Headlines.toggleUnread(id, 0);
} 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]";