Skip to content

Commit

Permalink
Fix webview crash on dropdown button click
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Mar 27, 2024
1 parent 25a85d5 commit bc4efed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/webview/newProjectPanel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ export class NewProjectPanel {
? `
<ul id="examples-list"></ul>
<!--<datalist id="examples-list">
<option value="${this._examples
<option value="\${this._examples
.map(e => e.searchKey)
.join(
'">example project</option>\n<option value="'
Expand Down
11 changes: 8 additions & 3 deletions web/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ window.toggleCreateFromExampleMode = function (forceOn, forceOff) {
projectNameInput.setAttribute('placeholder', 'Select an example');

window.removeExampleItems = window.removeExampleItems || function () {
// clear ul
examplesList.innerHTML = '';
if (examplesList !== null) {
// clear ul
examplesList.innerHTML = '';
}
};

window.examplesListSelect = window.examplesListSelect || function (exampleName) {
Expand All @@ -176,7 +178,7 @@ window.toggleCreateFromExampleMode = function (forceOn, forceOff) {

window.handleOutsideSuggestionsClick = window.handleOutsideSuggestionsClick || function (event) {
// check if the clicked element is not inside the examplesList
if (!examplesList.contains(event.target)) {
if (!examplesList.contains(event.target) && event.target !== projectNameDropdownButton) {
// click occurred outside the suggestions "popup" so remove the suggestions
removeExampleItems();
removeClickOutsideSuggestionsListener();
Expand Down Expand Up @@ -228,6 +230,9 @@ window.toggleCreateFromExampleMode = function (forceOn, forceOff) {
};

projectNameDropdownButton.addEventListener('click', (event) => {
// without this the webview crashes if project name input contains any text
event.preventDefault();

if (examplesList.childNodes.length === 0) {
// this is required to prevent the outside suggestions listener to fire after it has been
// added below
Expand Down

0 comments on commit bc4efed

Please sign in to comment.