mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
sort table by keyboard (#23171)
This commit is contained in:
@@ -11,9 +11,11 @@ import { KeybindingWeight, KeybindingsRegistry } from 'vs/platform/keybinding/co
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { HybridDataProvider } from 'sql/base/browser/ui/table/hybridDataProvider';
|
||||
|
||||
export const RESIZE_COLUMN_COMMAND_ID = 'table.resizeColumn';
|
||||
export const SHOW_COLUMN_MENU_COMMAND_ID = 'table.showColumnMenu';
|
||||
export const SORT_COLUMN_COMMAND_ID = 'table.sortColumn';
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: RESIZE_COLUMN_COMMAND_ID,
|
||||
@@ -42,6 +44,46 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
}
|
||||
});
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: SORT_COLUMN_COMMAND_ID,
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
when: InTable,
|
||||
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KeyO,
|
||||
handler: async (accessor) => {
|
||||
await handleTableCommand(accessor, async (table) => {
|
||||
const activeCell = table.grid.getActiveCell();
|
||||
if (activeCell && activeCell.cell >= 0) {
|
||||
const column = table.grid.getColumns()[activeCell.cell];
|
||||
if (column.sortable) {
|
||||
table.grid.sortColumnByActiveCell();
|
||||
} else if (table.getData() instanceof HybridDataProvider) {
|
||||
// For query editor/notebook, we don't use the slickgrid's builtin sorting, so handle it separately here.
|
||||
let columnState = table.grid.getSortColumns().find(c => c.columnId === column.id);
|
||||
if (columnState) {
|
||||
columnState.sortAsc = !columnState.sortAsc;
|
||||
} else {
|
||||
columnState = {
|
||||
columnId: column.id,
|
||||
sortAsc: true
|
||||
};
|
||||
}
|
||||
table.grid.setSortColumn(columnState.columnId, columnState.sortAsc);
|
||||
|
||||
const dataProvider = table.getData() as HybridDataProvider<Slick.SlickData>;
|
||||
await dataProvider.sort({
|
||||
grid: table.grid,
|
||||
multiColumnSort: false,
|
||||
sortCol: column,
|
||||
sortAsc: columnState.sortAsc
|
||||
});
|
||||
table.rerenderGrid();
|
||||
table.setActiveCell(activeCell.row, activeCell.cell);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
async function handleTableCommand(accessor: ServicesAccessor, action: (table: Table<any>) => Promise<void>) {
|
||||
const tableService = accessor.get(ITableService);
|
||||
const table = tableService.getActiveTable();
|
||||
|
||||
Reference in New Issue
Block a user