Skip to content

Commit

Permalink
Set cursor to insert end when inserting a file or tag in a prompt.
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jun 17, 2021
1 parent e5fea80 commit a59b05d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quickadd",
"name": "QuickAdd",
"version": "0.1.10",
"version": "0.1.11",
"minAppVersion": "0.12.00",
"description": "Quickly add new pages or content to your vault.",
"author": "Christian B. B. Houmann",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quickadd",
"version": "0.1.10",
"version": "0.1.11",
"description": "Quickly add new pages or content to your vault.",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/gui/silentFileAndTagSuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ export class SilentFileAndTagSuggester extends TextInputSuggest<string> {
const cursorPosition: number = this.inputEl.selectionStart;
const lastInputLength: number = this.lastInput.length;
const currentInputValue: string = this.inputEl.value;
let insertedEndPosition: number = 0;

if (this.lastInputType === TagOrFile.File) {
this.inputEl.value = this.getNewInputValueForFileName(currentInputValue, item, cursorPosition, lastInputLength);
insertedEndPosition = cursorPosition - lastInputLength + item.length + 2;
}

if (this.lastInputType === TagOrFile.Tag) {
this.inputEl.value = this.getNewInputValueForTag(currentInputValue, item, cursorPosition, lastInputLength);
insertedEndPosition = cursorPosition - lastInputLength + item.length - 1;
}

this.inputEl.trigger("input");
this.close();
this.inputEl.setSelectionRange(insertedEndPosition, insertedEndPosition);
}

private getNewInputValueForFileName(currentInputElValue: string, selectedItem: string, cursorPosition: number, lastInputLength: number): string {
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.1.10": "0.12.4"
"0.1.11": "0.12.4"
}

0 comments on commit a59b05d

Please sign in to comment.