Skip to content

Commit fc064f7

Browse files
authored
fix: fix misc selection issues (#1748)
**Summary:** This does a few things around improving context menus and selections. - It disables the command palette for things that shouldn't work in that way - It removes context menu items that are being displayed for multiple item selection (although they should only be for single item selection) - It updates tree view selection to work in the way described in #1744 NOTE: The most ideal path here imo is to automatically select an item when issuing the context menu (if it isn't part of the selections). I looked for a way to handle that but was unable. This change seems to work similar to how vscode does things natively. **Testing:** - [x] Made sure things displayed in the command palette worked as expected - [x] Made sure selection worked as expected
1 parent 53c5223 commit fc064f7

File tree

2 files changed

+105
-29
lines changed

2 files changed

+105
-29
lines changed
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
// Copyright © 2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { TreeView } from "vscode";
3+
import { TreeItem, TreeView } from "vscode";
44

55
/**
66
* Gets the selected items from a tree view based on the current selection state.
77
*
8-
* If multiple items are selected in the tree view, returns those selections.
9-
* If no item is passed or no selections exist, returns the tree view's selection.
10-
* Otherwise, returns the single clicked item.
8+
* If an item is present and is not part of selections, return the item. Otherwise,
9+
* return the selections.
1110
*
1211
* @param treeView - The VS Code TreeView instance
1312
* @param item - The item that was clicked/activated
1413
* @returns An array of selected items
1514
*/
16-
export function treeViewSelections<T>(
15+
export function treeViewSelections<T extends TreeItem>(
1716
treeView: TreeView<T>,
1817
item: T | undefined,
1918
): T[] {
20-
return treeView.selection.length > 1 || !item
21-
? [...treeView.selection]
22-
: [item];
19+
if (item) {
20+
const itemIsInSelection = treeView.selection.some(
21+
({ id }) => id === item.id,
22+
);
23+
if (itemIsInSelection) {
24+
return [...treeView.selection];
25+
}
26+
27+
return [item];
28+
}
29+
30+
return [...treeView.selection];
2331
}

package.json

Lines changed: 89 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,12 @@
967967
},
968968
{
969969
"command": "SAS.content.addFolderResource",
970-
"when": "viewItem =~ /createChild/ && view == contentdataprovider",
970+
"when": "viewItem =~ /createChild/ && view == contentdataprovider && !listMultiSelection",
971971
"group": "addgroup@0"
972972
},
973973
{
974974
"command": "SAS.content.addFileResource",
975-
"when": "viewItem =~ /createChild/ && view == contentdataprovider",
975+
"when": "viewItem =~ /createChild/ && view == contentdataprovider && !listMultiSelection",
976976
"group": "addgroup@1"
977977
},
978978
{
@@ -987,7 +987,7 @@
987987
},
988988
{
989989
"command": "SAS.content.copyPath",
990-
"when": "viewItem =~ /copyPath/ && view == contentdataprovider",
990+
"when": "viewItem =~ /copyPath/ && view == contentdataprovider && !listMultiSelection",
991991
"group": "copypathgroup@0"
992992
},
993993
{
@@ -1002,7 +1002,7 @@
10021002
},
10031003
{
10041004
"command": "SAS.content.convertNotebookToFlow",
1005-
"when": "viewItem =~ /convertNotebookToFlow/ && view == contentdataprovider",
1005+
"when": "viewItem =~ /convertNotebookToFlow/ && view == contentdataprovider && !listMultiSelection",
10061006
"group": "actionsgroup@0"
10071007
},
10081008
{
@@ -1160,27 +1160,47 @@
11601160
},
11611161
{
11621162
"when": "false",
1163-
"command": "SAS.content.restoreResource"
1163+
"command": "SAS.collapseAllLibraries"
11641164
},
11651165
{
11661166
"when": "false",
1167-
"command": "SAS.content.deleteResource"
1167+
"command": "SAS.content.addFileResource"
1168+
},
1169+
{
1170+
"when": "false",
1171+
"command": "SAS.content.addFolderResource"
1172+
},
1173+
{
1174+
"when": "false",
1175+
"command": "SAS.content.addToFavorites"
1176+
},
1177+
{
1178+
"when": "false",
1179+
"command": "SAS.content.collapseAllContent"
11681180
},
11691181
{
11701182
"when": "false",
11711183
"command": "SAS.content.convertNotebookToFlow"
11721184
},
11731185
{
11741186
"when": "false",
1175-
"command": "SAS.content.addFileResource"
1187+
"command": "SAS.content.copyPath"
11761188
},
11771189
{
11781190
"when": "false",
1179-
"command": "SAS.content.addFolderResource"
1191+
"command": "SAS.content.deleteResource"
11801192
},
11811193
{
11821194
"when": "false",
1183-
"command": "SAS.content.addToFavorites"
1195+
"command": "SAS.content.downloadResource"
1196+
},
1197+
{
1198+
"when": "false",
1199+
"command": "SAS.content.emptyRecycleBin"
1200+
},
1201+
{
1202+
"when": "false",
1203+
"command": "SAS.content.refreshContent"
11841204
},
11851205
{
11861206
"when": "false",
@@ -1192,19 +1212,19 @@
11921212
},
11931213
{
11941214
"when": "false",
1195-
"command": "SAS.content.refreshContent"
1215+
"command": "SAS.content.restoreResource"
11961216
},
11971217
{
11981218
"when": "false",
1199-
"command": "SAS.refreshLibraries"
1219+
"command": "SAS.content.uploadFileResource"
12001220
},
12011221
{
12021222
"when": "false",
1203-
"command": "SAS.content.collapseAllContent"
1223+
"command": "SAS.content.uploadFolderResource"
12041224
},
12051225
{
12061226
"when": "false",
1207-
"command": "SAS.collapseAllLibraries"
1227+
"command": "SAS.content.uploadResource"
12081228
},
12091229
{
12101230
"when": "false",
@@ -1216,39 +1236,87 @@
12161236
},
12171237
{
12181238
"when": "false",
1219-
"command": "SAS.showTableProperties"
1239+
"command": "SAS.notebook.export"
12201240
},
12211241
{
12221242
"when": "false",
1223-
"command": "SAS.content.downloadResource"
1243+
"command": "SAS.notebook.saveOutput"
12241244
},
12251245
{
12261246
"when": "false",
1227-
"command": "SAS.content.uploadResource"
1247+
"command": "SAS.refreshLibraries"
12281248
},
12291249
{
12301250
"when": "false",
1231-
"command": "SAS.content.uploadFileResource"
1251+
"command": "SAS.saveHTML"
12321252
},
12331253
{
12341254
"when": "false",
1235-
"command": "SAS.content.uploadFolderResource"
1255+
"command": "SAS.server.addFileResource"
12361256
},
12371257
{
12381258
"when": "false",
1239-
"command": "SAS.saveHTML"
1259+
"command": "SAS.server.addFolderResource"
12401260
},
12411261
{
12421262
"when": "false",
1243-
"command": "SAS.notebook.export"
1263+
"command": "SAS.server.addToFavorites"
12441264
},
12451265
{
12461266
"when": "false",
1247-
"command": "SAS.content.copyPath"
1267+
"command": "SAS.server.collapseAllContent"
1268+
},
1269+
{
1270+
"when": "false",
1271+
"command": "SAS.server.convertNotebookToFlow"
12481272
},
12491273
{
12501274
"when": "false",
12511275
"command": "SAS.server.copyPath"
1276+
},
1277+
{
1278+
"when": "false",
1279+
"command": "SAS.server.deleteResource"
1280+
},
1281+
{
1282+
"when": "false",
1283+
"command": "SAS.server.downloadResource"
1284+
},
1285+
{
1286+
"when": "false",
1287+
"command": "SAS.server.emptyRecycleBin"
1288+
},
1289+
{
1290+
"when": "false",
1291+
"command": "SAS.server.refreshContent"
1292+
},
1293+
{
1294+
"when": "false",
1295+
"command": "SAS.server.removeFromFavorites"
1296+
},
1297+
{
1298+
"when": "false",
1299+
"command": "SAS.server.renameResource"
1300+
},
1301+
{
1302+
"when": "false",
1303+
"command": "SAS.server.restoreResource"
1304+
},
1305+
{
1306+
"when": "false",
1307+
"command": "SAS.server.uploadFileResource"
1308+
},
1309+
{
1310+
"when": "false",
1311+
"command": "SAS.server.uploadFolderResource"
1312+
},
1313+
{
1314+
"when": "false",
1315+
"command": "SAS.server.uploadResource"
1316+
},
1317+
{
1318+
"when": "false",
1319+
"command": "SAS.showTableProperties"
12521320
}
12531321
],
12541322
"file/newFile": [

0 commit comments

Comments
 (0)