Skip to content

Commit dfea75a

Browse files
committed
update order of editor context menu, microsoft#9737
1 parent 5418b6c commit dfea75a

8 files changed

Lines changed: 63 additions & 27 deletions

File tree

src/vs/editor/contrib/clipboard/browser/clipboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function registerClipboardAction(desc: IClipboardCommand, alias: string, weight:
135135
id: desc.id,
136136
title: desc.label
137137
},
138-
group: `cutcopypaste`,
138+
group: `9_cutcopypaste`,
139139
order: weight,
140140
when: desc.kbExpr
141141
});

src/vs/editor/contrib/find/common/findController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ CommonEditorRegistry.registerEditorAction({
748748
primary: KeyMod.CtrlCmd | KeyCode.F2
749749
},
750750
menuOpts: {
751-
group: 'modification',
752-
order: 2,
751+
group: '1_modification',
752+
order: 1.2,
753753
kbExpr: KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_READONLY)
754754
}
755755
});

src/vs/editor/contrib/format/common/formatActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ CommonEditorRegistry.registerEditorAction({
231231
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I }
232232
},
233233
menuOpts: {
234-
group: 'modification',
235-
order: 10,
234+
group: '1_modification',
235+
order: 1.3,
236236
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasFormattingProvider)
237237
}
238238
});

src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ CommonEditorRegistry.registerEditorAction({
499499
},
500500
menuOpts: {
501501
group: 'navigation',
502-
order: 2,
502+
order: 1.2,
503503
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider)
504504
}
505505
});
@@ -519,7 +519,7 @@ CommonEditorRegistry.registerEditorAction({
519519
},
520520
menuOpts: {
521521
group: 'navigation',
522-
order: 1,
522+
order: 1.1,
523523
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasDefinitionProvider)
524524
}
525525
});

src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ CommonEditorRegistry.registerEditorAction({
137137
},
138138
menuOpts: {
139139
kbExpr: KbExpr.has(editorCommon.ModeContextKeys.hasReferenceProvider),
140-
group: 'navigation'
140+
group: 'navigation',
141+
order: 1.3
141142
}
142143
});
143144

src/vs/editor/contrib/rename/browser/rename.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ CommonEditorRegistry.registerEditorAction({
157157
primary: KeyCode.F2
158158
},
159159
menuOpts: {
160-
group: 'modification',
161-
order: 1,
160+
group: '1_modification',
161+
order: 1.1,
162162
kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasRenameProvider), KbExpr.not(KEYBINDING_CONTEXT_EDITOR_READONLY))
163163
}
164164
});

src/vs/platform/actions/common/menuService.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,27 @@ class Menu implements IMenu {
125125
let aGroup = a.group;
126126
let bGroup = b.group;
127127

128-
// Falsy groups come last
129-
if (!aGroup && bGroup) {
130-
return 1;
131-
} else if (aGroup && !bGroup) {
132-
return -1;
133-
}
128+
if (aGroup !== bGroup) {
134129

135-
// 'navigation' group comes first
136-
if (aGroup === 'navigation') {
137-
return -1;
138-
} else if (bGroup === 'navigation') {
139-
return 1;
140-
}
130+
// Falsy groups come last
131+
if (!aGroup) {
132+
return 1;
133+
} else if (!bGroup) {
134+
return -1;
135+
}
141136

142-
// lexical sort for groups
143-
if (aGroup < bGroup) {
144-
return -1;
145-
} else if(aGroup > bGroup) {
146-
return 1;
137+
// 'navigation' group comes first
138+
if (aGroup === 'navigation') {
139+
return -1;
140+
} else if (bGroup === 'navigation') {
141+
return 1;
142+
}
143+
144+
// lexical sort for groups
145+
let value = aGroup.localeCompare(bGroup);
146+
if (value !== 0) {
147+
return value;
148+
}
147149
}
148150

149151
// sort on priority - default is 0

src/vs/platform/actions/test/common/menuService.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,37 @@ suite('MenuService', function () {
153153
assert.equal(three.id, 'b');
154154
assert.equal(four.id, 'a');
155155
});
156+
157+
158+
test('in group sorting, special: navigation', function () {
159+
160+
disposables.push(MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
161+
command: { id: 'a', title: 'aaa' },
162+
group: 'navigation',
163+
order: 1.3
164+
}));
165+
166+
disposables.push(MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
167+
command: { id: 'b', title: 'fff' },
168+
group: 'navigation',
169+
order: 1.2
170+
}));
171+
172+
disposables.push(MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
173+
command: { id: 'c', title: 'zzz' },
174+
group: 'navigation',
175+
order: 1.1
176+
}));
177+
178+
const groups = menuService.createMenu(MenuId.ExplorerContext, keybindingService).getActions();
179+
180+
assert.equal(groups.length, 1);
181+
const [[, actions]] = groups;
182+
183+
assert.equal(actions.length, 3);
184+
const [one, two, three] = actions;
185+
assert.equal(one.id, 'c');
186+
assert.equal(two.id, 'b');
187+
assert.equal(three.id, 'a');
188+
});
156189
});

0 commit comments

Comments
 (0)