mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 03:59:05 +01:00
65 lines
2.1 KiB
Plaintext
65 lines
2.1 KiB
Plaintext
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
|
import SpacedUpdate from "../services/spaced_update.js";
|
|
import appContext, { type EventData } from "../components/app_context.js";
|
|
import branchService from "../services/branches.js";
|
|
import shortcutService from "../services/shortcuts.js";
|
|
|
|
export default class NoteTitleWidget extends NoteContextAwareWidget {
|
|
|
|
private $noteTitle!: JQuery<HTMLElement>;
|
|
private deleteNoteOnEscape: boolean;
|
|
private spacedUpdate: SpacedUpdate;
|
|
|
|
constructor() {
|
|
super();
|
|
|
|
this.deleteNoteOnEscape = false;
|
|
}
|
|
|
|
doRender() {
|
|
this.$widget = $(TPL);
|
|
this.$noteTitle = this.$widget.find(".note-title");
|
|
this.$noteTitle.on("blur", () => {
|
|
this.spacedUpdate.updateNowIfNecessary();
|
|
|
|
this.deleteNoteOnEscape = false;
|
|
});
|
|
|
|
shortcutService.bindElShortcut(this.$noteTitle, "esc", () => {
|
|
if (this.deleteNoteOnEscape && this.noteContext?.isActive() && this.noteContext?.note) {
|
|
branchService.deleteNotes(Object.values(this.noteContext.note.parentToBranch));
|
|
}
|
|
});
|
|
|
|
shortcutService.bindElShortcut(this.$noteTitle, "return", () => {
|
|
this.triggerCommand("focusOnDetail", { ntxId: this.noteContext?.ntxId });
|
|
});
|
|
}
|
|
|
|
async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) {
|
|
if (this.isNoteContext(noteContext.ntxId)) {
|
|
await this.spacedUpdate.updateNowIfNecessary();
|
|
}
|
|
}
|
|
|
|
async beforeNoteContextRemoveEvent({ ntxIds }: EventData<"beforeNoteContextRemove">) {
|
|
if (this.isNoteContext(ntxIds)) {
|
|
await this.spacedUpdate.updateNowIfNecessary();
|
|
}
|
|
}
|
|
|
|
focusOnTitleEvent() {
|
|
if (this.noteContext && this.noteContext.isActive()) {
|
|
this.$noteTitle.trigger("focus");
|
|
}
|
|
}
|
|
|
|
focusAndSelectTitleEvent({ isNewNote } = { isNewNote: false }) {
|
|
if (this.noteContext && this.noteContext.isActive()) {
|
|
this.$noteTitle.trigger("focus").trigger("select");
|
|
|
|
this.deleteNoteOnEscape = isNewNote;
|
|
}
|
|
}
|
|
}
|