Skip to content

Commit

Permalink
accept suggestion on space
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamonnguyen committed Sep 21, 2024
1 parent 49ad612 commit 94e3f71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "todotxt-codeblocks",
"name": "TodoTxt Codeblocks",
"version": "0.7.2",
"version": "0.7.3",
"minAppVersion": "0.15.0",
"description": "Manage your tasks inside codeblocks according to the Todo.txt specification.",
"author": "Benjamin Nguyen",
Expand Down
13 changes: 12 additions & 1 deletion src/component/EditItemModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class EditItemModal extends AutoCompleteableModal {
private _priorityDropDown: DropdownComponent;
submit: Setting;
protected _cursorPos: number;
private _hasSuggestion = false;

constructor(
itemText: string,
Expand Down Expand Up @@ -123,6 +124,16 @@ export default class EditItemModal extends AutoCompleteableModal {
.addEventListener('keyup', (e: KeyboardEvent) => {
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
updateCursorPos(e);
e.stopImmediatePropagation();
}
});
this.textComponent.inputEl
.addEventListener('keypress', (e: KeyboardEvent) => {
// accept suggestion on space
if (this._hasSuggestion && e.key === ' ') {
this._hasSuggestion = false;
this.textComponent.inputEl.selectionStart = this._cursorPos;
e.stopImmediatePropagation();
}
});
}
Expand Down Expand Up @@ -163,7 +174,7 @@ export default class EditItemModal extends AutoCompleteableModal {
this.updatePriorityDropDown();

//
if (!this.suggest(text, this.textComponent)) {
if (!(this._hasSuggestion = this.suggest(text, this.textComponent))) {
this.textComponent.setValue(text);
};
this._cursorPos = this.textComponent.inputEl.selectionEnd!;
Expand Down

0 comments on commit 94e3f71

Please # to comment.