From d3bf10ceb1252a27a8347ad771d8cfdd71c94b4b Mon Sep 17 00:00:00 2001 From: healthyCoder <36478181+healthyCoder@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:59:08 +0530 Subject: [PATCH] Fixing editable Title for Firefox and increasing max Title Lenght --- manifest.json | 2 +- popup/main.css | 1 + popup/warehouse.js | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 18d2e3c..dd889cd 100755 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Save for later", - "version": "1.2", + "version": "1.2.1", "description": "Save tabs in window to be used later", diff --git a/popup/main.css b/popup/main.css index 45e69c3..5562ed9 100755 --- a/popup/main.css +++ b/popup/main.css @@ -71,6 +71,7 @@ body { text-align: left; float: left; flex-grow: 1; + white-space: pre-wrap; } .iconBtn { diff --git a/popup/warehouse.js b/popup/warehouse.js index ed413fc..6de57d6 100755 --- a/popup/warehouse.js +++ b/popup/warehouse.js @@ -82,6 +82,10 @@ function createList(storeObj) { event.preventDefault(); handleTitleUpdate(obj, saveTitle) } + if (event.key === ' ') { + event.preventDefault(); + insertTextAtCaret(' '); + } }) saveTitle.addEventListener('focusout', () => { @@ -178,7 +182,7 @@ function validateAndUpdateTitle(obj, newTitleText) { } function santizeTitleName(titleText) { - const maxTitleLength = 29 + const maxTitleLength = 40 if (titleText.length >= maxTitleLength) { return titleText.substring(0, maxTitleLength); } @@ -230,6 +234,18 @@ function validateAndOpenSave(obj) { }); } +// Reference: https://stackoverflow.com/a/75505941/4688365 +function insertTextAtCaret(text) { + var sel, range; + sel = window.getSelection(); + if (sel && sel.getRangeAt && sel.rangeCount) { + range = sel.getRangeAt(0); + range.deleteContents(); + range.insertNode(document.createTextNode(text)); + range.collapse(); + } +} + async function storeIt(tabs) { // storeIt takes only the required data from what is provided by the browser and // stores it into the storage.local