mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-22 01:23:28 +01:00
Merge f79e76cb5b
into 1831b25dee
This commit is contained in:
commit
3640926a9a
1 changed files with 72 additions and 24 deletions
|
@ -415,7 +415,25 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
|
||||||
.setTooltip("Edit")
|
.setTooltip("Edit")
|
||||||
.setIcon("lucide-pencil")
|
.setIcon("lucide-pencil")
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
|
await handleEdit();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add double-click to edit functionality
|
||||||
|
nameField.label.addEventListener('dblclick', async () => {
|
||||||
|
if (!nameField.editing()) {
|
||||||
|
await handleEdit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleEdit() {
|
||||||
if (nameField.editing()) {
|
if (nameField.editing()) {
|
||||||
|
await saveChanges();
|
||||||
|
} else {
|
||||||
|
startEditing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveChanges() {
|
||||||
entry.name = nameField.endEdit();
|
entry.name = nameField.endEdit();
|
||||||
expandButton.buttonEl.style.display = null;
|
expandButton.buttonEl.style.display = null;
|
||||||
startField.endEdit();
|
startField.endEdit();
|
||||||
|
@ -426,9 +444,10 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
|
||||||
}
|
}
|
||||||
await saveTracker(tracker, getFile(), getSectionInfo());
|
await saveTracker(tracker, getFile(), getSectionInfo());
|
||||||
editButton.setIcon("lucide-pencil");
|
editButton.setIcon("lucide-pencil");
|
||||||
|
|
||||||
renderNameAsMarkdown(nameField.label, getFile, component);
|
renderNameAsMarkdown(nameField.label, getFile, component);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
function startEditing() {
|
||||||
nameField.beginEdit(entry.name);
|
nameField.beginEdit(entry.name);
|
||||||
expandButton.buttonEl.style.display = "none";
|
expandButton.buttonEl.style.display = "none";
|
||||||
// only allow editing start and end times if we don't have sub entries
|
// only allow editing start and end times if we don't have sub entries
|
||||||
|
@ -438,8 +457,23 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle
|
||||||
endField.beginEdit(entry.endTime);
|
endField.beginEdit(entry.endTime);
|
||||||
}
|
}
|
||||||
editButton.setIcon("lucide-check");
|
editButton.setIcon("lucide-check");
|
||||||
|
|
||||||
|
// Set up save/cancel handlers for keyboard shortcuts
|
||||||
|
nameField.onSave = startField.onSave = endField.onSave = async () => {
|
||||||
|
await saveChanges();
|
||||||
|
};
|
||||||
|
|
||||||
|
nameField.onCancel = startField.onCancel = endField.onCancel = () => {
|
||||||
|
nameField.endEdit();
|
||||||
|
startField.endEdit();
|
||||||
|
if (!entryRunning) {
|
||||||
|
endField.endEdit();
|
||||||
}
|
}
|
||||||
});
|
expandButton.buttonEl.style.display = null;
|
||||||
|
editButton.setIcon("lucide-pencil");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
new ButtonComponent(entryButtons)
|
new ButtonComponent(entryButtons)
|
||||||
.setClass("clickable-icon")
|
.setClass("clickable-icon")
|
||||||
.setTooltip("Remove")
|
.setTooltip("Remove")
|
||||||
|
@ -482,6 +516,8 @@ class EditableField {
|
||||||
cell: HTMLTableCellElement;
|
cell: HTMLTableCellElement;
|
||||||
label: HTMLSpanElement;
|
label: HTMLSpanElement;
|
||||||
box: TextComponent;
|
box: TextComponent;
|
||||||
|
onSave?: () => void;
|
||||||
|
onCancel?: () => void;
|
||||||
|
|
||||||
constructor(row: HTMLTableRowElement, indent: number, value: string) {
|
constructor(row: HTMLTableRowElement, indent: number, value: string) {
|
||||||
this.cell = row.createEl("td");
|
this.cell = row.createEl("td");
|
||||||
|
@ -490,6 +526,18 @@ class EditableField {
|
||||||
this.box = new TextComponent(this.cell).setValue(value);
|
this.box = new TextComponent(this.cell).setValue(value);
|
||||||
this.box.inputEl.addClass("simple-time-tracker-input");
|
this.box.inputEl.addClass("simple-time-tracker-input");
|
||||||
this.box.inputEl.hide();
|
this.box.inputEl.hide();
|
||||||
|
this.box.inputEl.addEventListener('keydown', (e: KeyboardEvent) => {
|
||||||
|
// Save with Ctrl/Cmd + Enter
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
this.onSave?.();
|
||||||
|
}
|
||||||
|
// Cancel with Escape
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
e.preventDefault();
|
||||||
|
this.onCancel?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
editing(): boolean {
|
editing(): boolean {
|
||||||
|
|
Loading…
Reference in a new issue