mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
various widget optimizations for faster note switching
This commit is contained in:
parent
66204811cf
commit
44ddcdd852
@ -486,7 +486,7 @@ window.Springy = function() {
|
|||||||
t._started = false;
|
t._started = false;
|
||||||
onRenderStop();
|
onRenderStop();
|
||||||
} else {
|
} else {
|
||||||
requestIdleCallback(step, { timeout: 10 });
|
requestIdleCallback(step, { timeout: 30 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,22 +433,6 @@ class AppContext {
|
|||||||
this.openTabsChangedListener();
|
this.openTabsChangedListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME non existent event
|
|
||||||
noteChangesSavedListener() {
|
|
||||||
const activeTabContext = this.getActiveTabContext();
|
|
||||||
|
|
||||||
if (!activeTabContext || !activeTabContext.note) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeTabContext.note.isProtected && protectedSessionHolder.isProtectedSessionAvailable()) {
|
|
||||||
protectedSessionHolder.touchProtectedSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
// run async
|
|
||||||
bundleService.executeRelationBundles(activeTabContext.note, 'runOnNoteChange', activeTabContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
activateNextTabListener() {
|
activateNextTabListener() {
|
||||||
const tabIdsInOrder = this.tabRow.getTabIdsInOrder();
|
const tabIdsInOrder = this.tabRow.getTabIdsInOrder();
|
||||||
const oldIdx = tabIdsInOrder.findIndex(tid => tid === this.activeTabId);
|
const oldIdx = tabIdsInOrder.findIndex(tid => tid === this.activeTabId);
|
||||||
|
@ -29,21 +29,8 @@ async function executeStartupBundles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeRelationBundles(note, relationName, tabContext) {
|
|
||||||
note.bundleCache = note.bundleCache || {};
|
|
||||||
|
|
||||||
if (!note.bundleCache[relationName]) {
|
|
||||||
note.bundleCache[relationName] = await server.get("script/relation/" + note.noteId + "/" + relationName);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const bundle of note.bundleCache[relationName]) {
|
|
||||||
await executeBundle(bundle, note, tabContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
executeBundle,
|
executeBundle,
|
||||||
getAndExecuteBundle,
|
getAndExecuteBundle,
|
||||||
executeStartupBundles,
|
executeStartupBundles
|
||||||
executeRelationBundles
|
|
||||||
}
|
}
|
@ -50,6 +50,8 @@ let maxKnownSyncId = 0;
|
|||||||
async function call(method, url, data, headers = {}) {
|
async function call(method, url, data, headers = {}) {
|
||||||
let resp;
|
let resp;
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
const ipc = require('electron').ipcRenderer;
|
const ipc = require('electron').ipcRenderer;
|
||||||
const requestId = i++;
|
const requestId = i++;
|
||||||
@ -74,6 +76,10 @@ async function call(method, url, data, headers = {}) {
|
|||||||
resp = await ajax(url, method, data, headers);
|
resp = await ajax(url, method, data, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const end = Date.now();
|
||||||
|
|
||||||
|
console.log(`${method} ${url} took ${end-start}ms`);
|
||||||
|
|
||||||
const maxSyncIdStr = resp.headers['trilium-max-sync-id'];
|
const maxSyncIdStr = resp.headers['trilium-max-sync-id'];
|
||||||
|
|
||||||
if (maxSyncIdStr && maxSyncIdStr.trim()) {
|
if (maxSyncIdStr && maxSyncIdStr.trim()) {
|
||||||
|
@ -66,9 +66,6 @@ class TabContext extends Component {
|
|||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
// should be done somewhere else ...
|
|
||||||
bundleService.executeRelationBundles(this.note, 'runOnNoteView', this);
|
|
||||||
|
|
||||||
if (this.note.isProtected && protectedSessionHolder.isProtectedSessionAvailable()) {
|
if (this.note.isProtected && protectedSessionHolder.isProtectedSessionAvailable()) {
|
||||||
// FIXME: there are probably more places where this should be done
|
// FIXME: there are probably more places where this should be done
|
||||||
protectedSessionHolder.touchProtectedSession();
|
protectedSessionHolder.touchProtectedSession();
|
||||||
|
@ -24,46 +24,44 @@ export default class AttributesWidget extends CollapsibleWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note) {
|
||||||
const attributes = await note.getAttributes();
|
|
||||||
const ownedAttributes = note.getOwnedAttributes();
|
const ownedAttributes = note.getOwnedAttributes();
|
||||||
|
|
||||||
if (attributes.length === 0) {
|
|
||||||
this.$body.text("No attributes yet...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $attributesContainer = $("<div>");
|
const $attributesContainer = $("<div>");
|
||||||
|
|
||||||
await this.renderAttributes(ownedAttributes, $attributesContainer);
|
await this.renderAttributes(ownedAttributes, $attributesContainer);
|
||||||
|
|
||||||
const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.tabContext.note.noteId);
|
const $inheritedAttrs = $("<span>").append($("<strong>").text("Inherited: "));
|
||||||
|
const $showInheritedAttributes = $("<a>")
|
||||||
|
.attr("href", "javascript:")
|
||||||
|
.text("+show inherited")
|
||||||
|
.on('click', async () => {
|
||||||
|
const attributes = await note.getAttributes();
|
||||||
|
const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.tabContext.note.noteId);
|
||||||
|
|
||||||
if (inheritedAttributes.length > 0) {
|
if (inheritedAttributes.length === 0) {
|
||||||
const $inheritedAttrs = $("<span>").append($("<strong>").text("Inherited: "));
|
$inheritedAttrs.text("No inherited attributes yet...");
|
||||||
const $showInheritedAttributes = $("<a>")
|
}
|
||||||
.attr("href", "javascript:")
|
else {
|
||||||
.text("+show inherited")
|
await this.renderAttributes(inheritedAttributes, $inheritedAttrs);
|
||||||
.on('click', () => {
|
}
|
||||||
$showInheritedAttributes.hide();
|
|
||||||
$inheritedAttrs.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
const $hideInheritedAttributes = $("<a>")
|
$inheritedAttrs.show();
|
||||||
.attr("href", "javascript:")
|
$showInheritedAttributes.hide();
|
||||||
.text("-hide inherited")
|
$hideInheritedAttributes.show();
|
||||||
.on('click', () => {
|
});
|
||||||
$showInheritedAttributes.show();
|
|
||||||
$inheritedAttrs.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
$attributesContainer.append($showInheritedAttributes);
|
const $hideInheritedAttributes = $("<a>")
|
||||||
$attributesContainer.append($inheritedAttrs);
|
.attr("href", "javascript:")
|
||||||
|
.text("-hide inherited")
|
||||||
|
.on('click', () => {
|
||||||
|
$showInheritedAttributes.show();
|
||||||
|
$hideInheritedAttributes.hide();
|
||||||
|
$inheritedAttrs.empty().hide();
|
||||||
|
});
|
||||||
|
|
||||||
await this.renderAttributes(inheritedAttributes, $inheritedAttrs);
|
$attributesContainer.append($showInheritedAttributes, $inheritedAttrs, $hideInheritedAttributes);
|
||||||
|
|
||||||
$inheritedAttrs.append($hideInheritedAttributes);
|
$inheritedAttrs.hide();
|
||||||
$inheritedAttrs.hide();
|
$hideInheritedAttributes.hide();
|
||||||
}
|
|
||||||
|
|
||||||
this.$body.empty().append($attributesContainer);
|
this.$body.empty().append($attributesContainer);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,18 @@ export default class LinkMapWidget extends CollapsibleWidget {
|
|||||||
return [$showFullButton];
|
return [$showFullButton];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noteSwitched() {
|
||||||
|
const noteId = this.noteId;
|
||||||
|
|
||||||
|
// avoid executing this expensive operation multiple times when just going through notes (with keyboard especially)
|
||||||
|
// until the users settles on a note
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.noteId === noteId) {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note) {
|
||||||
this.$body.css('opacity', 0);
|
this.$body.css('opacity', 0);
|
||||||
this.$body.html(TPL);
|
this.$body.html(TPL);
|
||||||
|
@ -26,47 +26,48 @@ export default class NotePathsWidget extends TabAwareWidget {
|
|||||||
this.$notePathList = this.$widget.find(".note-path-list");
|
this.$notePathList = this.$widget.find(".note-path-list");
|
||||||
this.$notePathCount = this.$widget.find(".note-path-count");
|
this.$notePathCount = this.$widget.find(".note-path-count");
|
||||||
|
|
||||||
|
this.$widget.on('show.bs.dropdown', () => this.renderDropdown());
|
||||||
|
|
||||||
return this.$widget;
|
return this.$widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note, notePath) {
|
async refreshWithNote(note, notePath) {
|
||||||
if (note.noteId === 'root') {
|
const pathCount = note.noteId === 'root'
|
||||||
// root doesn't have any parent, but it's still technically 1 path
|
? 1 // root doesn't have any parent, but it's still technically 1 path
|
||||||
|
: note.getBranchIds().length;
|
||||||
|
|
||||||
this.$notePathCount.html("1 path");
|
this.$notePathCount.html(pathCount + " path" + (pathCount > 1 ? "s" : ""));
|
||||||
|
}
|
||||||
|
|
||||||
this.$notePathList.empty();
|
async renderDropdown() {
|
||||||
|
this.$notePathList.empty();
|
||||||
|
|
||||||
|
if (this.noteId === 'root') {
|
||||||
await this.addPath('root', true);
|
await this.addPath('root', true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
const parents = await note.getParentNotes();
|
|
||||||
|
|
||||||
this.$notePathCount.html(parents.length + " path" + (parents.length > 1 ? "s" : ""));
|
const pathSegments = this.notePath.split("/");
|
||||||
this.$notePathList.empty();
|
const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
|
||||||
|
|
||||||
const pathSegments = notePath.split("/");
|
for (const parentNote of await this.note.getParentNotes()) {
|
||||||
const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
|
const parentNotePath = await treeService.getSomeNotePath(parentNote);
|
||||||
|
// this is to avoid having root notes leading '/'
|
||||||
|
const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId;
|
||||||
|
const isCurrent = activeNoteParentNoteId === parentNote.noteId;
|
||||||
|
|
||||||
for (const parentNote of parents) {
|
await this.addPath(notePath, isCurrent);
|
||||||
const parentNotePath = await treeService.getSomeNotePath(parentNote);
|
|
||||||
// this is to avoid having root notes leading '/'
|
|
||||||
const notePath = parentNotePath ? (parentNotePath + '/' + note.noteId) : note.noteId;
|
|
||||||
const isCurrent = activeNoteParentNoteId === parentNote.noteId;
|
|
||||||
|
|
||||||
await this.addPath(notePath, isCurrent);
|
|
||||||
}
|
|
||||||
|
|
||||||
const cloneLink = $("<div>")
|
|
||||||
.addClass("dropdown-item")
|
|
||||||
.append(
|
|
||||||
$('<button class="btn btn-sm">')
|
|
||||||
.text('Clone note to new location...')
|
|
||||||
.on('click', () => import("../dialogs/clone_to.js").then(d => d.showDialog([note.noteId])))
|
|
||||||
);
|
|
||||||
|
|
||||||
this.$notePathList.append(cloneLink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cloneLink = $("<div>")
|
||||||
|
.addClass("dropdown-item")
|
||||||
|
.append(
|
||||||
|
$('<button class="btn btn-sm">')
|
||||||
|
.text('Clone note to new location...')
|
||||||
|
.on('click', () => import("../dialogs/clone_to.js").then(d => d.showDialog([this.noteId])))
|
||||||
|
);
|
||||||
|
|
||||||
|
this.$notePathList.append(cloneLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addPath(notePath, isCurrent) {
|
async addPath(notePath, isCurrent) {
|
||||||
@ -75,9 +76,12 @@ export default class NotePathsWidget extends TabAwareWidget {
|
|||||||
const noteLink = await linkService.createNoteLink(notePath, {title});
|
const noteLink = await linkService.createNoteLink(notePath, {title});
|
||||||
|
|
||||||
noteLink
|
noteLink
|
||||||
.addClass("no-tooltip-preview")
|
|
||||||
.addClass("dropdown-item");
|
.addClass("dropdown-item");
|
||||||
|
|
||||||
|
noteLink
|
||||||
|
.find('a')
|
||||||
|
.addClass("no-tooltip-preview");
|
||||||
|
|
||||||
if (isCurrent) {
|
if (isCurrent) {
|
||||||
noteLink.addClass("current");
|
noteLink.addClass("current");
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,18 @@ class NoteRevisionsWidget extends CollapsibleWidget {
|
|||||||
return [$showFullButton];
|
return [$showFullButton];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noteSwitched() {
|
||||||
|
const noteId = this.noteId;
|
||||||
|
|
||||||
|
// avoid executing this expensive operation multiple times when just going through notes (with keyboard especially)
|
||||||
|
// until the users settles on a note
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.noteId === noteId) {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note) {
|
||||||
const revisionItems = await server.get(`notes/${note.noteId}/revisions`);
|
const revisionItems = await server.get(`notes/${note.noteId}/revisions`);
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ export default class NoteTypeWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** actual body is rendered lazily on note-type button click */
|
/** actual body is rendered lazily on note-type button click */
|
||||||
async renderDropdown() {console.log("AAAAAAAAAAAAAAAAAAA");
|
async renderDropdown() {
|
||||||
this.$noteTypeDropdown.empty();
|
this.$noteTypeDropdown.empty();
|
||||||
|
|
||||||
for (const noteType of NOTE_TYPES.filter(nt => nt.selectable)) {
|
for (const noteType of NOTE_TYPES.filter(nt => nt.selectable)) {
|
||||||
@ -130,6 +130,7 @@ export default class NoteTypeWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async confirmChangeIfContent() {
|
async confirmChangeIfContent() {
|
||||||
|
// FIXME
|
||||||
if (!this.tabContext.getComponent().getContent()) {
|
if (!this.tabContext.getComponent().getContent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,20 @@ export default class SimilarNotesWidget extends CollapsibleWidget {
|
|||||||
|
|
||||||
getMaxHeight() { return "200px"; }
|
getMaxHeight() { return "200px"; }
|
||||||
|
|
||||||
|
noteSwitched() {
|
||||||
|
const noteId = this.noteId;
|
||||||
|
|
||||||
|
this.$body.empty();
|
||||||
|
|
||||||
|
// avoid executing this expensive operation multiple times when just going through notes (with keyboard especially)
|
||||||
|
// until the users settles on a note
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.noteId === noteId) {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note) {
|
||||||
// remember which title was when we found the similar notes
|
// remember which title was when we found the similar notes
|
||||||
this.title = note.title;
|
this.title = note.title;
|
||||||
|
@ -268,7 +268,7 @@ div.ui-tooltip {
|
|||||||
color: #888 !important;
|
color: #888 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-menu a:hover:not(.disabled), li.dropdown-item:hover:not(.disabled), div.dropdown-item:hover:not(.disabled) {
|
.dropdown-menu a:hover:not(.disabled), .dropdown-item:hover:not(.disabled) {
|
||||||
color: var(--hover-item-text-color) !important;
|
color: var(--hover-item-text-color) !important;
|
||||||
background-color: var(--hover-item-background-color) !important;
|
background-color: var(--hover-item-background-color) !important;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -415,7 +415,7 @@ function evaluateSimilarity(text1, text2, noteId, results) {
|
|||||||
*/
|
*/
|
||||||
function setImmediatePromise() {
|
function setImmediatePromise() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setImmediate(() => resolve());
|
setTimeout(() => resolve(), 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user