From a59b05d4e51f3a1b0c760cd5b5f420512d517d1d Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Thu, 17 Jun 2021 12:17:31 +0200 Subject: [PATCH] Set cursor to insert end when inserting a file or tag in a prompt. --- manifest.json | 2 +- package.json | 2 +- src/gui/silentFileAndTagSuggester.ts | 4 ++++ versions.json | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index c8d4ba1..36d807e 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/package.json b/package.json index 6ca9f89..c756d0e 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/gui/silentFileAndTagSuggester.ts b/src/gui/silentFileAndTagSuggester.ts index 555c2ec..23d08b1 100644 --- a/src/gui/silentFileAndTagSuggester.ts +++ b/src/gui/silentFileAndTagSuggester.ts @@ -52,17 +52,21 @@ export class SilentFileAndTagSuggester extends TextInputSuggest { 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 { diff --git a/versions.json b/versions.json index 8e71c91..d685382 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "0.1.10": "0.12.4" + "0.1.11": "0.12.4" }