Skip to content

Commit

Permalink
feat: add vim mode
Browse files Browse the repository at this point in the history
  • Loading branch information
invm committed Sep 17, 2023
1 parent 87547fe commit a8c0c4c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@codemirror/lang-sql": "^6.5.2",
"@codemirror/state": "^6.2.1",
"@codemirror/view": "^6.14.1",
"@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",
Expand Down
40 changes: 40 additions & 0 deletions pnpm-lock.yaml

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

61 changes: 42 additions & 19 deletions src/components/Screens/Console/Content/QueryTab/QueryTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
} from "@codemirror/view";
import { sql } from "@codemirror/lang-sql";
import { dracula } from "@uiw/codemirror-theme-dracula";
import { vim } from "@replit/codemirror-vim";
import { format } from "sql-formatter";
import { invoke } from "@tauri-apps/api";
import { EditIcon, FireIcon } from "components/UI/Icons";
import { EditIcon, FireIcon, VimIcon } from "components/UI/Icons";
import { useAppSelector } from "services/Context";
import { QueryContentTabData } from "services/ConnectionTabs";
import { QueryResult } from "interfaces";
Expand All @@ -37,23 +38,7 @@ export const QueryTextArea = (props: {
updateStore,
},
} = useAppSelector();

const onPrevClick = () => {
props.setIdx(
(props.idx() -
1 +
(getActiveContentTab().data as QueryContentTabData).result_sets
.length) %
(getActiveContentTab().data as QueryContentTabData).result_sets.length
);
};

const onNextClick = () => {
props.setIdx(
(props.idx() + 1) %
(getActiveContentTab().data as QueryContentTabData).result_sets.length
);
};
const [vimModeOn, setVimModeOn] = createSignal(true);

const updateQueryText = async (query: string) => {
setActiveContentQueryTabData({ query });
Expand All @@ -76,6 +61,7 @@ export const QueryTextArea = (props: {
createExtension(() => highlightWhitespace());
createExtension(() => highlightActiveLine());
createExtension(dracula);
createExtension(() => (vimModeOn() ? vim() : []));
const { setFocused } = createEditorFocus(editorView);

const lineWrapping = EditorView.lineWrapping;
Expand Down Expand Up @@ -138,10 +124,27 @@ export const QueryTextArea = (props: {
});
});

const onPrevClick = () => {
props.setIdx(
(props.idx() -
1 +
(getActiveContentTab().data as QueryContentTabData).result_sets
.length) %
(getActiveContentTab().data as QueryContentTabData).result_sets.length
);
};

const onNextClick = () => {
props.setIdx(
(props.idx() + 1) %
(getActiveContentTab().data as QueryContentTabData).result_sets.length
);
};

return (
<div class="flex-1 flex flex-col">
<div class="w-full px-2 py-1 bg-base-100 border-b-2 border-accent flex items-center">
<div>
<div class="flex items-center">
<div
class="tooltip tooltip-primary tooltip-bottom"
data-tip={t("components.console.actions.format")}
Expand All @@ -164,6 +167,26 @@ export const QueryTextArea = (props: {
<FireIcon />
</button>
</div>

<div
class="tooltip tooltip-primary tooltip-bottom"
data-tip={t("components.console.actions.vim_mode_on")}
>
<div class="flex items-center mr-2">
<span class="mr-2">
<VimIcon />
</span>
<input
type="checkbox"
class="toggle"
classList={{
"toggle-success": vimModeOn(),
}}
checked={vimModeOn()}
onChange={() => setVimModeOn((v) => !v)}
/>
</div>
</div>
</div>

<Show when={getActiveContentTab().error}>
Expand Down
15 changes: 15 additions & 0 deletions src/components/UI/Icons/Vim.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const VimIcon = () => {
return (
<svg
class="w-5 h-5 text-secondary"
fill="green"
width="800px"
height="800px"
viewBox="0 0 24 24"
role="img"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M24 11.986h-.027l-4.318-4.318 4.303-4.414V1.461l-.649-.648h-8.198l-.66.605v1.045L12.015.027V0L12 .014 11.986 0v.027l-1.29 1.291-.538-.539H2.035l-.638.692v1.885l.616.616h.72v5.31L.027 11.987H0L.014 12 0 12.014h.027l2.706 2.706v6.467l.907.523h2.322l1.857-1.904 4.166 4.166V24l.015-.014.014.014v-.028l2.51-2.509h.485c.111 0 .211-.07.25-.179l.146-.426c.028-.084.012-.172-.037-.239l1.462-1.462-.612 1.962c-.043.141.036.289.177.332.025.008.052.012.078.012h1.824c.106-.001.201-.064.243-.163l.165-.394c.025-.065.024-.138-.004-.203-.027-.065-.08-.116-.146-.142-.029-.012-.062-.019-.097-.02h-.075l.84-2.644h1.232l-1.016 3.221c-.043.141.036.289.176.332.025.008.052.012.079.012h2.002c.11 0 .207-.066.248-.17l.164-.428c.051-.138-.021-.29-.158-.341-.029-.011-.06-.017-.091-.017h-.145l1.131-3.673c.027-.082.012-.173-.039-.24l-.375-.504-.003-.005c-.051-.064-.127-.102-.209-.102h-1.436c-.071 0-.141.03-.19.081l-.4.439h-.624l-.042-.046 4.445-4.445H24L23.986 12l.014-.014zM9.838 21.139l1.579-4.509h-.501l.297-.304h1.659l-1.563 4.555h.623l-.079.258H9.838zm3.695-7.516l.15.151-.269.922-.225.226h-.969l-.181-.181.311-.871.288-.247h.895zM5.59 20.829H3.877l-.262-.15V3.091H2.379l-.1-.1V1.815l.143-.154h7.371l.213.214v1.108l-.142.173H8.785v8.688l8.807-8.688h-2.086l-.175-.188V1.805l.121-.111h7.49l.132.133v1.07L12.979 13.25h-.373c-.015-.001-.028 0-.042.001l-.02.003c-.045.01-.086.03-.119.06l-.343.295-.004.003c-.033.031-.059.069-.073.111l-.296.83-6.119 6.276zm14.768-3.952l.474-.519h1.334l.309.415-1.265 4.107h.493l-.08.209H19.84l1.124-3.564h-2.015l-1.077 3.391h.424l-.073.174h-1.605l1.107-3.548h-2.096l-1.062 3.339h.436l-.072.209H13.27l1.514-4.46H14.198l.091-.271h1.65l.519.537h.906l.491-.554h1.061l.489.535h.953z" />
</svg>
);
};
1 change: 1 addition & 0 deletions src/components/UI/Icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './Edit'
export * from './Fire'
export * from './Pen'
export * from './ThreeDots'
export * from './Vim'

3 changes: 2 additions & 1 deletion src/utils/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"query": "Query",
"actions": {
"format": "Format",
"execute": "Execute"
"execute": "Execute",
"vim_mode_on": "Vim mode on"
},
"zero_results": "0 rows retuned",
"result_set": "Result set ",
Expand Down

0 comments on commit a8c0c4c

Please sign in to comment.