Skip to content

Commit

Permalink
fix(List/Matrix View): 🐛 Sort by altField first, then regular note na…
Browse files Browse the repository at this point in the history
…me (Fix #206)
  • Loading branch information
SkepticMystic committed Dec 16, 2021
1 parent 4c45603 commit 5914cfb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
29 changes: 19 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24548,19 +24548,21 @@ class MatrixView extends require$$0.ItemView {
return Promise.resolve();
}
getAlt(node) {
var _a;
const { altLinkFields } = this.plugin.settings;
let alt = null;
if (altLinkFields.length) {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
altLinkFields.forEach((altLinkField) => {
var _a;
alt = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter) === null || _a === void 0 ? void 0 : _a[altLinkField];
});
for (const altField of altLinkFields) {
const value = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter) === null || _a === void 0 ? void 0 : _a[altField];
if (value)
return value;
}
}
}
return alt;
else
return null;
}
// ANCHOR Remove duplicate implied links
removeDuplicateImplied(reals, implieds) {
Expand Down Expand Up @@ -24629,7 +24631,16 @@ class MatrixView extends require$$0.ItemView {
const { alphaSortAsc } = settings;
const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip];
if (settings.enableAlphaSort) {
squares.forEach((sq) => sq.sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1));
squares.forEach((sq) => sq.sort((a, b) => {
var _a, _b;
return ((_a = a.alt) !== null && _a !== void 0 ? _a : a.to) < ((_b = b.alt) !== null && _b !== void 0 ? _b : b.to)
? alphaSortAsc
? -1
: 1
: alphaSortAsc
? 1
: -1;
}));
}
squares.forEach((sq) => sq.sort((a, b) => a.order - b.order));
loglevel.info([
Expand Down Expand Up @@ -24691,9 +24702,7 @@ class MatrixView extends require$$0.ItemView {
await this.draw();
};
});
contentEl.createEl("button", { text: "↻", attr: { "aria-label": "Refresh Index" } }, (el) => {
el.onclick = async () => await this.plugin.refreshIndex();
});
contentEl.createEl("button", { text: "↻", attr: { "aria-label": "Refresh Index" } }, (el) => (el.onclick = async () => await this.plugin.refreshIndex()));
contentEl.createEl("button", {
text: settings.alphaSortAsc ? "↗" : "↘",
attr: { "aria-label": "Alphabetical sorting order" },
Expand Down
12 changes: 8 additions & 4 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,13 @@ export default class MatrixView extends ItemView {
if (settings.enableAlphaSort) {
squares.forEach((sq) =>
sq.sort((a, b) =>
a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1
(a.alt ?? a.to) < (b.alt ?? b.to)
? alphaSortAsc
? -1
: 1
: alphaSortAsc
? 1
: -1
)
);
}
Expand Down Expand Up @@ -287,9 +293,7 @@ export default class MatrixView extends ItemView {
contentEl.createEl(
"button",
{ text: "↻", attr: { "aria-label": "Refresh Index" } },
(el) => {
el.onclick = async () => await this.plugin.refreshIndex();
}
(el) => (el.onclick = async () => await this.plugin.refreshIndex())
);

contentEl.createEl(
Expand Down

0 comments on commit 5914cfb

Please sign in to comment.