Skip to content

Commit aab9ae2

Browse files
committed
Sort settings
1 parent 07a7aa3 commit aab9ae2

File tree

5 files changed

+66
-28
lines changed

5 files changed

+66
-28
lines changed

js/main/commands.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,41 @@ App.update_command_history = (cmd) => {
1212
}
1313

1414
App.sort_commands = () => {
15-
App.sorted_commands = App.commands.slice(0)
15+
function sort(what) {
16+
let items = `command_${what}_items`
17+
App[items] = App.commands.slice(0)
18+
let setting = App.get_setting(`command_${what}_sort`)
1619

17-
if (!App.get_setting(`sort_commands`)) {
18-
return
19-
}
20+
if (setting === `none`) {
21+
// Do nothing
22+
}
23+
else if (setting === `recent`) {
24+
App[items].sort((a, b) => {
25+
let ia = App.command_history.indexOf(a.cmd)
26+
let ib = App.command_history.indexOf(b.cmd)
2027

21-
App.sorted_commands.sort((a, b) => {
22-
let ia = App.command_history.indexOf(a.cmd)
23-
let ib = App.command_history.indexOf(b.cmd)
28+
if ((ia !== -1) && (ib !== -1)) {
29+
return ia - ib
30+
}
2431

25-
if ((ia !== -1) && (ib !== -1)) {
26-
return ia - ib
27-
}
32+
if (ia !== -1) {
33+
return -1
34+
}
2835

29-
if (ia !== -1) {
30-
return -1
36+
if (ib !== -1) {
37+
return 1
38+
}
39+
})
3140
}
32-
33-
if (ib !== -1) {
34-
return 1
41+
else if (setting === `alpha`) {
42+
App[items].sort((a, b) => {
43+
return a.name.localeCompare(b.name)
44+
})
3545
}
36-
})
46+
}
47+
48+
sort(`palette`)
49+
sort(`menu`)
3750
}
3851

3952
App.get_command = (cmd) => {

js/main/filter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,10 @@ App.do_filter_2 = (mode) => {
973973
}
974974
else {
975975
show = text.includes(value)
976-
}
977976

978-
if (!show && tooltip) {
979-
show = tooltip.includes(value)
977+
if (!show && tooltip) {
978+
show = tooltip.includes(value)
979+
}
980980
}
981981

982982
if (show) {

js/main/palette.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ App.fill_palette = () => {
175175
container.innerHTML = ``
176176
let num = 0
177177

178-
for (let cmd of App.sorted_commands) {
178+
for (let cmd of App.command_palette_items) {
179179
if (cmd.skip_palette) {
180180
continue
181181
}

js/main/setting_props.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,36 @@ App.build_settings = () => {
257257
})
258258
},
259259
},
260+
command_palette_sort: {
261+
name: `Command Palette Sort`,
262+
type: `menu`,
263+
value: `recent`,
264+
setup: (key) => {
265+
App.settings_make_menu(key, [
266+
{text: `None`, value: `none`},
267+
{text: `Recent`, value: `recent`},
268+
{text: `Alpha`, value: `alpha`},
269+
])
270+
},
271+
actions: [`commands`],
272+
info: `How to sort the command palette`,
273+
version: 1,
274+
},
275+
command_menu_sort: {
276+
name: `Command Menu Sort`,
277+
type: `menu`,
278+
value: `none`,
279+
setup: (key) => {
280+
App.settings_make_menu(key, [
281+
{text: `None`, value: `none`},
282+
{text: `Recent`, value: `recent`},
283+
{text: `Alpha`, value: `alpha`},
284+
])
285+
},
286+
actions: [`commands`],
287+
info: `How to sort the command menus`,
288+
version: 1,
289+
},
260290
tooltips_mode: {
261291
name: `Tooltips Mode`,
262292
type: `menu`,
@@ -272,6 +302,7 @@ App.build_settings = () => {
272302
{text: `Arrows`, value: `arrows`},
273303
])
274304
},
305+
actions: [`commands`],
275306
info: `How to present the tooltips of items`,
276307
version: 1,
277308
},
@@ -5199,13 +5230,6 @@ App.build_settings = () => {
51995230
info: `Allow rounded corners in some parts of the interface`,
52005231
version: 1,
52015232
},
5202-
sort_commands: {
5203-
name: `Sort Commands`,
5204-
type: `checkbox`,
5205-
value: true,
5206-
info: `Sort commands in the Palette by recent use`,
5207-
version: 1,
5208-
},
52095233
check_commands: {
52105234
name: `Check Commands`,
52115235
type: `checkbox`,

js/main/settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ App.settings_do_actions = (actions) => {
1010
else if (action === `commands`) {
1111
App.setup_commands()
1212
App.build_setting_cmds()
13+
App.fill_palette()
1314
}
1415
else if (action === `filters`) {
1516
App.start_filter_debouncers()
@@ -1096,7 +1097,7 @@ App.settings_commands = (include_none, include_sep) => {
10961097

10971098
App.add_setting_headers(items, include_none, include_sep)
10981099

1099-
for (let cmd of App.commands) {
1100+
for (let cmd of App.command_menu_items) {
11001101
if (cmd.skip_settings) {
11011102
continue
11021103
}

0 commit comments

Comments
 (0)