mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-15 05:45:20 +00:00
Add vim support to code viewer
This commit is contained in:
parent
e7616b43ad
commit
c73325d8ce
3 changed files with 33 additions and 19 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
"@radix-ui/react-scroll-area": "^1.1.0",
|
"@radix-ui/react-scroll-area": "^1.1.0",
|
||||||
"@radix-ui/react-separator": "^1.1.0",
|
"@radix-ui/react-separator": "^1.1.0",
|
||||||
"@radix-ui/react-slot": "^1.1.0",
|
"@radix-ui/react-slot": "^1.1.0",
|
||||||
|
"@replit/codemirror-vim": "^6.2.1",
|
||||||
"@uiw/react-codemirror": "^4.23.0",
|
"@uiw/react-codemirror": "^4.23.0",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,31 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Separator } from "@/components/ui/separator";
|
|
||||||
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
|
|
||||||
import { defaultKeymap } from "@codemirror/commands";
|
|
||||||
import { javascript } from "@codemirror/lang-javascript";
|
|
||||||
import { EditorView, keymap, ViewPlugin, ViewUpdate } from "@codemirror/view";
|
|
||||||
import { SymbolIcon, FileIcon, Cross1Icon } from "@radix-ui/react-icons";
|
|
||||||
import { ScrollArea, Scrollbar } from "@radix-ui/react-scroll-area";
|
|
||||||
import CodeMirror from '@uiw/react-codemirror';
|
|
||||||
import Image from "next/image";
|
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import { useEffect, useMemo, useState } from "react";
|
|
||||||
import { useDebouncedCallback } from 'use-debounce';
|
|
||||||
import logoLight from "../../public/sb_logo_light.png";
|
|
||||||
import logoDark from "../../public/sb_logo_dark.png";
|
|
||||||
import {
|
import {
|
||||||
ResizableHandle,
|
ResizableHandle,
|
||||||
ResizablePanel,
|
ResizablePanel,
|
||||||
ResizablePanelGroup,
|
ResizablePanelGroup,
|
||||||
} from "@/components/ui/resizable";
|
} from "@/components/ui/resizable";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
|
||||||
import { GetSourceResponse, pathQueryParamName, repoQueryParamName } from "@/lib/api";
|
import { GetSourceResponse, pathQueryParamName, repoQueryParamName } from "@/lib/api";
|
||||||
import { createPathWithQueryParams } from "@/lib/utils";
|
import { createPathWithQueryParams } from "@/lib/utils";
|
||||||
import { ThemeSelectorButton } from "./themeSelectorButton";
|
import { defaultKeymap } from "@codemirror/commands";
|
||||||
|
import { javascript } from "@codemirror/lang-javascript";
|
||||||
|
import { EditorView, keymap, ViewPlugin, ViewUpdate } from "@codemirror/view";
|
||||||
|
import { Cross1Icon, FileIcon, SymbolIcon } from "@radix-ui/react-icons";
|
||||||
|
import { ScrollArea, Scrollbar } from "@radix-ui/react-scroll-area";
|
||||||
|
import { vim } from "@replit/codemirror-vim";
|
||||||
|
import CodeMirror from '@uiw/react-codemirror';
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
import { Button } from "@/components/ui/button";
|
import Image from "next/image";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { useDebouncedCallback } from 'use-debounce';
|
||||||
|
import logoDark from "../../public/sb_logo_dark.png";
|
||||||
|
import logoLight from "../../public/sb_logo_light.png";
|
||||||
|
import { ThemeSelectorButton } from "./themeSelectorButton";
|
||||||
|
|
||||||
interface ZoekMatch {
|
interface ZoekMatch {
|
||||||
URL: string,
|
URL: string,
|
||||||
|
|
@ -158,6 +159,7 @@ export default function Home() {
|
||||||
code={code}
|
code={code}
|
||||||
filepath={filepath}
|
filepath={filepath}
|
||||||
onClose={() => setIsCodePanelOpen(false)}
|
onClose={() => setIsCodePanelOpen(false)}
|
||||||
|
keymapType="default"
|
||||||
/>
|
/>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
)}
|
)}
|
||||||
|
|
@ -169,12 +171,14 @@ export default function Home() {
|
||||||
interface CodeEditorProps {
|
interface CodeEditorProps {
|
||||||
code: string;
|
code: string;
|
||||||
filepath: string;
|
filepath: string;
|
||||||
|
keymapType: "default" | "vim";
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CodeEditor = ({
|
const CodeEditor = ({
|
||||||
code,
|
code,
|
||||||
filepath,
|
filepath,
|
||||||
|
keymapType,
|
||||||
onClose,
|
onClose,
|
||||||
}: CodeEditorProps) => {
|
}: CodeEditorProps) => {
|
||||||
const { theme: _theme, systemTheme } = useTheme();
|
const { theme: _theme, systemTheme } = useTheme();
|
||||||
|
|
@ -208,7 +212,7 @@ const CodeEditor = ({
|
||||||
<div className="flex flex-row bg-cyan-200 dark:bg-cyan-900 items-center justify-between pr-3">
|
<div className="flex flex-row bg-cyan-200 dark:bg-cyan-900 items-center justify-between pr-3">
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
<div
|
<div
|
||||||
style={{width: `${gutterWidth}px`}}
|
style={{ width: `${gutterWidth}px` }}
|
||||||
className="flex justify-center items-center"
|
className="flex justify-center items-center"
|
||||||
>
|
>
|
||||||
<FileIcon className="h-4 w-4" />
|
<FileIcon className="h-4 w-4" />
|
||||||
|
|
@ -224,11 +228,15 @@ const CodeEditor = ({
|
||||||
</div>
|
</div>
|
||||||
<ScrollArea className="h-full overflow-y-auto">
|
<ScrollArea className="h-full overflow-y-auto">
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
editable={false}
|
readOnly={true}
|
||||||
value={code}
|
value={code}
|
||||||
theme={theme === "dark" ? "dark" : "light"}
|
theme={theme === "dark" ? "dark" : "light"}
|
||||||
extensions={[
|
extensions={[
|
||||||
keymap.of(defaultKeymap),
|
...(keymapType === "vim" ? [
|
||||||
|
vim(),
|
||||||
|
] : [
|
||||||
|
keymap.of(defaultKeymap),
|
||||||
|
]),
|
||||||
javascript(),
|
javascript(),
|
||||||
gutterWidthPlugin.extension,
|
gutterWidthPlugin.extension,
|
||||||
EditorView.updateListener.of(update => {
|
EditorView.updateListener.of(update => {
|
||||||
|
|
|
||||||
|
|
@ -576,6 +576,11 @@
|
||||||
resolved "https://registry.yarnpkg.com/@radix-ui/rect/-/rect-1.1.0.tgz#f817d1d3265ac5415dadc67edab30ae196696438"
|
resolved "https://registry.yarnpkg.com/@radix-ui/rect/-/rect-1.1.0.tgz#f817d1d3265ac5415dadc67edab30ae196696438"
|
||||||
integrity sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==
|
integrity sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==
|
||||||
|
|
||||||
|
"@replit/codemirror-vim@^6.2.1":
|
||||||
|
version "6.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@replit/codemirror-vim/-/codemirror-vim-6.2.1.tgz#6673ff4be93b7da03d303ef37d6cbfa5f647b74b"
|
||||||
|
integrity sha512-qDAcGSHBYU5RrdO//qCmD8K9t6vbP327iCj/iqrkVnjbrpFhrjOt92weGXGHmTNRh16cUtkUZ7Xq7rZf+8HVow==
|
||||||
|
|
||||||
"@rushstack/eslint-patch@^1.3.3":
|
"@rushstack/eslint-patch@^1.3.3":
|
||||||
version "1.10.4"
|
version "1.10.4"
|
||||||
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.4.tgz#427d5549943a9c6fce808e39ea64dbe60d4047f1"
|
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.4.tgz#427d5549943a9c6fce808e39ea64dbe60d4047f1"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue