autocollapse notes after period of inactivity + some other changes, #1192

This commit is contained in:
zadam
2020-08-17 20:58:34 +02:00
parent 53b39e2e82
commit f24e27dadd
13 changed files with 81 additions and 46 deletions

View File

@@ -26,6 +26,8 @@ class NoteComplement {
/** @param {string} */
this.utcDateModified = row.utcDateModified;
// "combined" date modified give larger out of note's and note_content's dateModified
/** @param {string} */
this.combinedDateModified = row.combinedDateModified;

View File

@@ -85,6 +85,11 @@ class TabContext extends Component {
return treeCache.notes[this.noteId];
}
/** @property {string[]} */
get notePathArray() {
return this.notePath ? this.notePath.split('/') : [];
}
/** @return {NoteComplement} */
async getNoteComplement() {
if (!this.noteId) {

View File

@@ -16,7 +16,7 @@ class TreeContextMenu {
this.treeWidget = treeWidget;
this.node = node;
}
async show(e) {
contextMenu.show({
x: e.pageX,
@@ -111,7 +111,14 @@ class TreeContextMenu {
const notePath = treeService.getNotePath(this.node);
if (command === 'openInTab') {
appContext.tabManager.openTabWithNote(notePath);
const start = Date.now();
await this.node.load(true);
console.log("Reload took", Date.now() - start, "ms");
// appContext.tabManager.openTabWithNote(notePath);
}
else if (command === "insertNoteAfter") {
const parentNoteId = this.node.data.parentNoteId;
@@ -136,4 +143,4 @@ class TreeContextMenu {
}
}
export default TreeContextMenu;
export default TreeContextMenu;

View File

@@ -63,7 +63,7 @@ const TPL = `
<div class="attr-is-owned-by"></div>
<table class="attr-edit-table">
<tr>
<tr title="Attribute name can be composed of alphanumeric characters, colon and underscore only">
<th>Name:</th>
<td><input type="text" class="attr-input-name form-control" /></td>
</tr>
@@ -159,15 +159,15 @@ const ATTR_TITLES = {
};
export default class AttributeDetailWidget extends TabAwareWidget {
isEnabled() {
async refresh() {
// this widget is not activated in a standard way
return false;
}
doRender() {
this.relatedNotesSpacedUpdate = new SpacedUpdate(async () => this.updateRelatedNotes(), 1000);
this.$widget = $(TPL);
this.contentSized();
this.$title = this.$widget.find('.attr-detail-title');
@@ -280,7 +280,7 @@ export default class AttributeDetailWidget extends TabAwareWidget {
return;
}
console.log("RENDERING");
this.attrType = this.getAttrType(attribute);
const attrName =
@@ -373,6 +373,8 @@ export default class AttributeDetailWidget extends TabAwareWidget {
this.$widget.outerHeight() + y > $(window).height() - 50
? $(window).height() - y - 50
: 10000);
console.log("RENDERING DONE");
}
async updateRelatedNotes() {

View File

@@ -116,7 +116,7 @@ export default class AttributeListWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.overflowing();
this.$promotedExpander = this.$widget.find('.attr-promoted-expander');
this.$allAttrWrapper = this.$widget.find('.all-attr-wrapper');

View File

@@ -30,6 +30,11 @@ class BasicWidget extends Component {
return this;
}
overflowing() {
this.css('contain', 'none');
return this;
}
collapsible() {
this.css('min-height', '0');
return this;

View File

@@ -93,7 +93,7 @@ const TPL = `
export default class NoteActionsWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.overflowing();
this.$showSourceButton = this.$widget.find('.show-source-button');

View File

@@ -312,6 +312,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
scrollParent: this.$tree,
minExpandLevel: 2, // root can't be collapsed
click: (event, data) => {
this.activityDetected();
const targetType = data.targetType;
const node = data.node;
@@ -911,6 +913,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
async refresh() {
this.toggleInt(this.isEnabled());
this.activityDetected();
const oldActiveNode = this.getActiveNode();
let oldActiveNodeFocused = false;
@@ -956,7 +960,44 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
}
activityDetected() {
if (this.autoCollapseTimeoutId) {
clearTimeout(this.autoCollapseTimeoutId);
}
this.autoCollapseTimeoutId = setTimeout(() => {
/*
* We're collapsing notes after period of inactivity to "cleanup" the tree - users rarely
* collapse the notes and the tree becomes unusuably large.
* Some context: https://github.com/zadam/trilium/issues/1192
*/
const noteIdsToKeepExpanded = new Set(
appContext.tabManager.getTabContexts()
.map(tc => tc.notePathArray)
.flat()
);
let noneCollapsedYet = true;
this.tree.getRootNode().visit(node => {
if (node.isExpanded() && !noteIdsToKeepExpanded.has(node.data.noteId)) {
node.setExpanded(false);
if (noneCollapsedYet) {
toastService.showMessage("Auto collapsing notes after inactivity...");
noneCollapsedYet = false;
}
console.log("Auto collapsed", node.data.noteId);
}
}, false);
}, 600 * 1000);
}
async entitiesReloadedEvent({loadResults}) {
this.activityDetected();
if (loadResults.isEmptyForTree()) {
return;
}

View File

@@ -34,7 +34,7 @@ const TPL = `
export default class NoteTypeWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.overflowing();
this.$widget.on('show.bs.dropdown', () => this.renderDropdown());

View File

@@ -825,3 +825,7 @@ body {
.ck.ck-mentions > .ck-list__item {
max-width: 600px;
}
ul.fancytree-container li {
contain: layout paint;
}

View File

@@ -66,7 +66,7 @@
<link href="libraries/ckeditor/ckeditor-content.css" rel="stylesheet">
<!-- Include Fancytree skin and library -->
<link href="libraries/fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet">
<link href="libraries/fancytree/skin-win8/ui.fancytree.css" rel="stylesheet">
<script src="libraries/fancytree/jquery.fancytree-all-deps.min.js"></script>
<script src="libraries/jquery.hotkeys.js"></script>