Skip to content

Commit

Permalink
fix: Retain selection when switching modes
Browse files Browse the repository at this point in the history
  • Loading branch information
kewisch committed Nov 30, 2024
1 parent 0807d90 commit c134d36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/popup/baseItemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ export default class BaseItemList extends HTMLElement {
}

repopulate() {
let selectedFolderId = this.selected?.itemNode.id;
let selectNode = null;

let lowerSearchTerm = this.searchValue.toLowerCase();
this.#clearItems();

Expand All @@ -526,22 +529,35 @@ export default class BaseItemList extends HTMLElement {
let canIncludeItem = this.#navigateOnly || item.canFileMessages;

if (!mismatch && canIncludeItem) {
this._addItem(item, BaseItemList.MODE_SEARCH);
let node = this._addItem(item, BaseItemList.MODE_SEARCH);
if (selectedFolderId && item.id == selectedFolderId) {
selectNode = node;
}
}
}
} else if (this.defaultItems) {
for (let item of this.defaultItems) {
if (this.#navigateOnly || item.canFileMessages) {
this._addItem(item, BaseItemList.MODE_DEFAULT);
let node = this._addItem(item, BaseItemList.MODE_DEFAULT);
if (selectedFolderId && item.id == selectedFolderId) {
selectNode = node;
}
}
}
} else {
for (let item of this.allItems) {
if (this.#navigateOnly || item.canFileMessages) {
this._addItem(item, BaseItemList.MODE_ALL);
let node = this._addItem(item, BaseItemList.MODE_ALL);
if (selectedFolderId && item.id == selectedFolderId) {
selectNode = node;
}
}
}
}

if (selectNode) {
this.selected = selectNode;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/popup/folderList.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TBFolderList extends BaseItemList {

_addItem(folderNode, mode) {
if (this.#excludeSet.has(folderNode.id)) {
return;
return null;
}

// let depth = mode == BaseItemList.MODE_ALL ? (folderNode.path.match(/\//g) || []).length - 1 : 0;
Expand Down Expand Up @@ -131,6 +131,7 @@ class TBFolderList extends BaseItemList {
}

body.appendChild(item);
return body.lastElementChild;
}

initItems(allItems, defaultItems, showFolderPath, excludeSet) {
Expand Down
1 change: 1 addition & 0 deletions src/popup/tagList.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TBTagList extends BaseItemList {
item.querySelector(".item").itemNode = tag;

body.appendChild(item);
return body.lastElementChild;
}
}

Expand Down

0 comments on commit c134d36

Please sign in to comment.