Skip to content

Commit

Permalink
Auto grow text areas
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso committed Oct 13, 2023
1 parent 884dfe6 commit 82a03d3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions assets/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
}

textarea {
height: calc(1.5em + .75rem + calc(var(--bs-border-width)))
height: calc(1.5em + .75rem + calc(var(--bs-border-width)));
overflow: hidden;
}

button {
Expand Down Expand Up @@ -182,7 +183,7 @@
</div>

<div class="text-center">
<a href="https://github.com/forgetso/search-replace/releases/tag/1.6.10" target="_blank" class="link-body-emphasis">Version 1.6.10</a>
<a href="https://github.com/forgetso/search-replace/releases/tag/1.6.11" target="_blank" class="link-body-emphasis">Version 1.6.11</a>
</div>
</body>

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"https://*/*"
],
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "1.6.10",
"version": "1.6.11",
"options_page": "assets/options.html"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "search_and_replace",
"version": "1.6.10",
"version": "1.6.11",
"resolutions": {
"author": "Chris Taylor <[email protected]>"
},
Expand Down
14 changes: 14 additions & 0 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ window.addEventListener('DOMContentLoaded', function () {
}
}

// Handler for auto resizing the textareas
for (const elementName of ['searchTerm', 'replaceTerm']) {
;(<HTMLTextAreaElement>document.getElementById(elementName)).addEventListener('input', function () {
autoGrow(this)
})
}

// Click handler for historyContent element. Will take the search term and replace term from the history item and populate the input fields
;(<HTMLDivElement>document.getElementById('historyContent')).addEventListener('click', historyItemClickHandler)

Expand All @@ -99,6 +106,13 @@ async function storeTermsHandler(e) {
await storeTerms(e, false)
}

// function to change the height of the textarea to fit the content
function autoGrow(element) {
console.log('change height')
element.style.height = ''
element.style.height = element.scrollHeight + 'px'
}

// function to expand or contract the history section
function historyHeaderClickHandler(e) {
e.preventDefault()
Expand Down

0 comments on commit 82a03d3

Please sign in to comment.