Polish time entry tag autocomplete PR

This commit is contained in:
callumalpass 2026-04-26 18:05:25 +10:00
parent 5be68f4d8b
commit 6abcac10f4
3 changed files with 42 additions and 22 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View file

@ -152,7 +152,7 @@ export class TimeEntryEditorModal extends Modal {
const newDate = new Date(startInput.value);
if (!isNaN(newDate.getTime())) {
entry.startTime = newDate.toISOString();
this.updateTotalDisplay();
this.updateTotalDisplay();
}
});
@ -172,37 +172,37 @@ export class TimeEntryEditorModal extends Modal {
const newDate = new Date(endInput.value);
if (!isNaN(newDate.getTime())) {
entry.endTime = newDate.toISOString();
this.updateTotalDisplay();
this.updateTotalDisplay();
}
} else {
entry.endTime = undefined;
this.updateTotalDisplay();
this.updateTotalDisplay();
}
});
// Description
const descriptionSetting = new Setting(timeContainer)
.setName(this.translate("modals.timeEntryEditor.description"));
const descriptionSetting = new Setting(timeContainer)
.setName(this.translate("modals.timeEntryEditor.description"));
const editorContainer = descriptionSetting.controlEl.createDiv({
cls: "time-entry-editor-modal__description-editor-container",
});
const editorContainer = descriptionSetting.controlEl.createDiv({
cls: "time-entry-editor-modal__description-editor-container",
});
const editor = createTaskModalMarkdownEditor(this.app, editorContainer, {
value: entry.description || "",
placeholder: this.translate("modals.timeEntryEditor.descriptionPlaceholder"),
cls: "time-entry-editor-modal__description-editor",
onChange: (value) => {
entry.description = value || undefined;
},
onSubmit: () => this.save(),
onEscape: () => {},
onTab: () => false,
});
const editor = createTaskModalMarkdownEditor(this.app, editorContainer, {
value: entry.description || "",
placeholder: this.translate("modals.timeEntryEditor.descriptionPlaceholder"),
cls: "time-entry-editor-modal__description-editor",
onChange: (value) => {
entry.description = value || undefined;
},
onSubmit: () => this.save(),
onEscape: () => this.close(),
onTab: () => false,
});
if (editor) {
this.descriptionEditors.push(editor);
}
if (editor) {
this.descriptionEditors.push(editor);
}
}
private cleanupDescriptionEditors(): void {

View file

@ -40,6 +40,26 @@ describe("TimeEntryEditorModal", () => {
]);
});
it("closes the modal when Escape is pressed inside the markdown editor", () => {
const plugin = PluginFactory.createMockPlugin();
const task = TaskFactory.createTask({
timeEntries: [TimeEntryFactory.createEntry()],
});
createTaskModalMarkdownEditorMock.mockReturnValue({
destroy: jest.fn(),
} as any);
const modal = new TimeEntryEditorModal(plugin.app as any, plugin as any, task, jest.fn());
const closeSpy = jest.spyOn(modal, "close").mockImplementation(jest.fn());
modal.onOpen();
const editorOptions = createTaskModalMarkdownEditorMock.mock.calls[0][2];
editorOptions.onEscape();
expect(closeSpy).toHaveBeenCalledTimes(1);
});
it("destroys markdown editors before rerendering and when closing", () => {
const plugin = PluginFactory.createMockPlugin();
const task = TaskFactory.createTask({