ace2_inner: Simplify handler for Ctrl-@ (show authors)

pull/5153/head
Richard Hansen 2021-08-16 00:22:43 -04:00
parent 88057eade2
commit fed950e809
1 changed files with 10 additions and 50 deletions

View File

@ -2637,67 +2637,27 @@ function Ace2Inner(editorInfo, cssManagers) {
// TODO: Still work when authorship colors have been cleared // TODO: Still work when authorship colors have been cleared
// TODO: i18n // TODO: i18n
// TODO: There appears to be a race condition or so. // TODO: There appears to be a race condition or so.
const authors = []; const authorIds = new Set();
let author = null;
if (alineAttrs) { if (alineAttrs) {
const opIter = Changeset.opIterator(alineAttrs); const opIter = Changeset.opIterator(alineAttrs);
while (opIter.hasNext()) { while (opIter.hasNext()) {
const op = opIter.next(); const op = opIter.next();
const authorId = Changeset.opAttributeValue(op, 'author', apool); const authorId = Changeset.opAttributeValue(op, 'author', apool);
if (authorId !== '') authorIds.add(authorId);
// Only push unique authors and ones with values
if (authors.indexOf(authorId) === -1 && authorId !== '') {
authors.push(authorId);
} }
} }
} const idToName = new Map(parent.parent.pad.userList().map((a) => [a.userId, a.name]));
const myId = parent.parent.clientVars.userId;
let authorString; const authors =
const authorNames = []; [...authorIds].map((id) => id === myId ? 'me' : idToName.get(id) || 'unknown');
if (authors.length === 0) {
authorString = 'No author information is available';
} else {
// Known authors info, both current and historical
const padAuthors = parent.parent.pad.userList();
let authorObj = {};
for (const authorId of authors) {
for (const padAuthor of padAuthors) {
// If the person doing the lookup is the author..
if (padAuthor.userId === authorId) {
if (parent.parent.clientVars.userId === authorId) {
authorObj = {
name: 'Me',
};
} else {
authorObj = padAuthor;
}
}
}
if (!authorObj) {
author = 'Unknown';
continue;
}
author = authorObj.name;
if (!author) author = 'Unknown';
authorNames.push(author);
}
}
if (authors.length === 1) {
authorString = `The author of this line is ${authorNames[0]}`;
}
if (authors.length > 1) {
authorString = `The authors of this line are ${authorNames.join(' & ')}`;
}
parent.parent.$.gritter.add({ parent.parent.$.gritter.add({
// (string | mandatory) the heading of the notification
title: 'Line Authors', title: 'Line Authors',
// (string | mandatory) the text inside the notification text:
text: authorString, authors.length === 0 ? 'No author information is available'
// (bool | optional) if you want it to fade out on its own or just sit there : authors.length === 1 ? `The author of this line is ${authors[0]}`
: `The authors of this line are ${authors.join(' & ')}`,
sticky: false, sticky: false,
// (int | optional) the time you want it to be alive for before fading out
time: '4000', time: '4000',
}); });
} }