Skip to content

Commit

Permalink
feat: add execute and result sets global shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
invm committed Sep 17, 2023
1 parent 9ddb937 commit 1b29492
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@replit/codemirror-vim": "^6.0.14",
"@solid-primitives/event-bus": "^1.0.8",
"@tauri-apps/api": "^1.4.0",
"@types/tabulator-tables": "^5.4.10",
"@uiw/codemirror-theme-dracula": "^4.21.7",
"fuse.js": "^6.6.2",
"i18next": "^23.1.0",
Expand All @@ -38,6 +37,7 @@
},
"devDependencies": {
"@tauri-apps/cli": "^1.4.0",
"@types/tabulator-tables": "^5.4.10",
"@types/node": "^20.3.2",
"autoprefixer": "^10.4.14",
"daisyui": "^3.1.7",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions src/components/CommandPalette/CommandPaletteContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { actions } from "./actions";
import { actions, commandPaletteEmitter } from "./actions";
import { useAppSelector } from "services/Context";
import { CommandPalette, Root } from "solid-command-palette";
import { JSX } from "solid-js/jsx-runtime";
import { onMount } from "solid-js";
import { QueryContentTabData } from "services/ConnectionTabs";

export interface ActionsContext {
showThemeSwitcher: () => void;
Expand All @@ -17,6 +18,7 @@ export const CommandPaletteContext = (props: { children: JSX.Element }) => {
setActiveConnection,
addContentTab,
removeActiveContentTab,
getActiveContentTab,
},
} = useAppSelector();

Expand All @@ -35,19 +37,34 @@ export const CommandPaletteContext = (props: { children: JSX.Element }) => {
const number = e.code.startsWith("Digit")
? +e.code.replace("Digit", "")
: null;
const { ctrlKey, metaKey, altKey, key, preventDefault, code } = e;
if (
(e.ctrlKey || e.metaKey || e.altKey) &&
(ctrlKey || metaKey || altKey) &&
number &&
number > 0 &&
number <= 9
) {
e.preventDefault();
if (e.altKey) setActiveContentTab(number);
preventDefault();
if (altKey) setActiveContentTab(number);
else setActiveConnection(number - 1);
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyT") {
} else if ((ctrlKey || metaKey) && code === "KeyT") {
e.preventDefault();
if (e.shiftKey) removeActiveContentTab();
else addContentTab();
} else if (code === "KeyE" && (ctrlKey || metaKey)) {
commandPaletteEmitter.emit("execute", undefined);
} else if (
key === "p" &&
ctrlKey &&
(getActiveContentTab().data as QueryContentTabData).result_sets.length
) {
commandPaletteEmitter.emit("prev-result-set", undefined);
} else if (
key === "n" &&
ctrlKey &&
(getActiveContentTab().data as QueryContentTabData).result_sets.length
) {
commandPaletteEmitter.emit("next-result-set", undefined);
}
};
});
Expand Down
3 changes: 3 additions & 0 deletions src/components/CommandPalette/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ActionsContext } from "./CommandPaletteContext";

export const commandPaletteEmitter = createEmitter<{
"focus-query-text-area": boolean;
"next-result-set": undefined;
"prev-result-set": undefined;
"execute": undefined;
}>();

const showThemeSwitcher = defineAction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@codemirror/view";
import { sql } from "@codemirror/lang-sql";
import { dracula } from "@uiw/codemirror-theme-dracula";
import { Vim, vim } from "@replit/codemirror-vim";
import { vim } from "@replit/codemirror-vim";
import { format } from "sql-formatter";
import { invoke } from "@tauri-apps/api";
import { EditIcon, FireIcon, VimIcon } from "components/UI/Icons";
Expand Down Expand Up @@ -139,6 +139,11 @@ export const QueryTextArea = (props: {
setFocused(true);
}, 1);
});
commandPaletteEmitter.on("next-result-set", onNextClick);
commandPaletteEmitter.on("prev-result-set", onPrevClick);
commandPaletteEmitter.on("execute", async () => {
await onExecute();
});
});

const onPrevClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ResultsTable = (props: { data: Record<string, any>[] }) => {
title: k,
field: k,
resizeable: true,
// editor: 'input' as const,
}));

new Tabulator("#results-table", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { useAppSelector } from "services/Context";
import {
createEffect,
createSignal,
For,
Match,
on,
onMount,
Switch,
} from "solid-js";
import { createEffect, createSignal, For, Match, Switch } from "solid-js";
import { invoke } from "@tauri-apps/api";
import { TableStructureResult, TableStrucureEntities } from "interfaces";
import { t } from "utils/i18n";
Expand All @@ -29,21 +21,19 @@ export const TableStructureTab = () => {
const activeConnection = getActiveConnection();
const activeTab = getActiveContentTab();

createEffect(
on(getActiveContentTab(), async () => {
try {
const { columns, indices, triggers, constraints } =
await invoke<TableStructureResult>("get_table_structure", {
connId: activeConnection.id,
tableName: (activeTab.data as TableStructureContentTabData).table,
});
setData({ columns, indices, triggers, constraints });
} catch (error) {
addError(error);
}
setLoading(false);
})
);
createEffect(async () => {
try {
const { columns, indices, triggers, constraints } =
await invoke<TableStructureResult>("get_table_structure", {
connId: activeConnection.id,
tableName: (activeTab.data as TableStructureContentTabData).table,
});
setData({ columns, indices, triggers, constraints });
} catch (error) {
addError(error);
}
setLoading(false);
});

return (
<div class="bg-base-200 rounded-tl-md p-2 h-full">
Expand Down
44 changes: 25 additions & 19 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
-webkit-text-size-adjust: 100%;
}

html, body {
html,
body {
margin: 0;
overflow: hidden;
-webkit-user-select: none; /* Safari */
Expand Down Expand Up @@ -45,39 +46,39 @@ input::-webkit-inner-spin-button {
}

[contenteditable] {
-webkit-user-select: text;
user-select: text;
-webkit-user-select: text;
user-select: text;
}

/* Firefox */
input[type=number] {
input[type="number"] {
-moz-appearance: textfield;
}

::-webkit-scrollbar {
width: 10px;
width: 10px;
}

::-webkit-scrollbar-track {
background: #888;
border-radius: 5px;
background: #888;
border-radius: 5px;
}

::-webkit-scrollbar-thumb {
background: #000;
border-radius: 5px;
background: #000;
border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
background: #555;
background: #555;
}

.app-input {
@apply block w-full p-2 border border-gray-300 rounded-lg bg-base-100 sm:text-sm focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 py-1.5 dark:placeholder-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500 text-base h-[32px];
}

.app-checkbox{
@apply w-4 h-4 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 focus:ring-2 dark:border-gray-600;
.app-checkbox {
@apply w-4 h-4 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 focus:ring-2 dark:border-gray-600;
}

.app-select {
Expand All @@ -96,7 +97,7 @@ input[type=number] {
outline-style: auto !important;
}

.tab-lifted.tab-active:not(.tab-disabled):not([disabled]){
.tab-lifted.tab-active:not(.tab-disabled):not([disabled]) {
border-width: 0px;
}

Expand All @@ -112,12 +113,12 @@ dialog {
color: inherit;
}

.gutter-vertical:hover{
.gutter-vertical:hover {
@apply bg-neutral-content rounded-lg;
cursor: row-resize;
}

.gutter-horizontal:hover{
.gutter-horizontal:hover {
@apply bg-neutral-content rounded-lg;
cursor: col-resize;
}
Expand All @@ -144,7 +145,8 @@ dialog {
@apply bg-base-300 text-base-content !important;
}

.tabulator-tableholder .tabulator-table, .tabulator-footer {
.tabulator-tableholder .tabulator-table,
.tabulator-footer {
@apply border-neutral-focus !important;
}

Expand All @@ -156,6 +158,10 @@ dialog {
@apply text-base-content !important;
}

.tabulator-row.tabulator-selectable:hover {
@apply bg-base-300 cursor-pointer font-semibold text-base text-primary !important;
}

#results {
-webkit-user-select: auto; /* Safari */
-ms-user-select: auto; /* IE 10 and IE 11 */
Expand Down

0 comments on commit 1b29492

Please sign in to comment.