Skip to content

Commit

Permalink
fix(search): Ensure that opened windows are sorted before any other l…
Browse files Browse the repository at this point in the history
…auncher options
  • Loading branch information
mmstick committed Jan 12, 2021
1 parent 7d8cba8 commit fb9f2ed
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/dialog_launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class Launcher extends search.Search {

this.last_plugin = null

let windows = new Array()

this.service.query(pattern, (plugin, response) => {
if (response.event === "queried") {
for (const selection of response.selections) {
Expand Down Expand Up @@ -97,7 +99,7 @@ export class Launcher extends search.Search {
|| contains_pattern(window.meta.get_title(), needles);

if (retain) {
this.options.push(window_selection(ext, window, this.icon_size()))
windows.push(window_selection(ext, window, this.icon_size()))
}
}

Expand All @@ -123,8 +125,7 @@ export class Launcher extends search.Search {
}
}

// Sort the list of matched selections
this.options.sort((a, b) => {
const sorter = (a: launch.SearchOption, b: launch.SearchOption) => {
const a_name = a.title.toLowerCase()
const b_name = b.title.toLowerCase()

Expand All @@ -143,7 +144,12 @@ export class Launcher extends search.Search {
}

return a_name_weight > b_name_weight ? 1 : 0
});
}

// Sort the list of matched selections
windows.sort(sorter)
this.options.sort(sorter);
this.options = windows.concat(this.options)

// Truncate excess items from the list
this.options.splice(this.list_max());
Expand Down

0 comments on commit fb9f2ed

Please sign in to comment.