Files
Trilium/src/public/app/widgets/containers/scrolling_container.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

import Container from "./container.js";
export default class ScrollingContainer extends Container {
constructor() {
super();
this.class("scrolling-container");
2025-01-09 18:07:02 +02:00
this.css("overflow", "auto");
this.css("scroll-behavior", "smooth");
this.css("position", "relative");
}
2025-01-09 18:07:02 +02:00
setNoteContextEvent({ noteContext }) {
/** @var {NoteContext} */
this.noteContext = noteContext;
}
2025-01-09 18:07:02 +02:00
async noteSwitchedEvent({ noteContext, notePath }) {
this.$widget.scrollTop(0);
}
2025-01-09 18:07:02 +02:00
async noteSwitchedAndActivatedEvent({ noteContext, notePath }) {
this.noteContext = noteContext;
this.$widget.scrollTop(0);
}
2025-01-09 18:07:02 +02:00
async activeContextChangedEvent({ noteContext }) {
this.noteContext = noteContext;
}
handleEventInChildren(name, data) {
2025-01-09 18:07:02 +02:00
if (name === "readOnlyTemporarilyDisabled" && this.noteContext && this.noteContext.ntxId === data.noteContext.ntxId) {
const scrollTop = this.$widget.scrollTop();
const promise = super.handleEventInChildren(name, data);
2022-05-26 16:29:54 +02:00
// there seems to be some asynchronicity, and we need to wait a bit before scrolling
promise.then(() => setTimeout(() => this.$widget.scrollTop(scrollTop), 500));
2021-06-26 17:08:50 +02:00
return promise;
2025-01-09 18:07:02 +02:00
} else {
return super.handleEventInChildren(name, data);
}
}
2022-05-26 16:29:54 +02:00
2025-01-09 18:07:02 +02:00
scrollContainerToCommand({ position }) {
2022-05-26 16:29:54 +02:00
this.$widget.scrollTop(position);
}
}