feat(nvim): word wrap and snap tree width to characters

This commit is contained in:
Pihkaal
2024-06-01 11:58:41 +02:00
parent 68b483f89c
commit cf2637d33e
5 changed files with 36 additions and 28 deletions

View File

@@ -85,7 +85,7 @@ export const Kitty = (props: {
ref={container} ref={container}
> >
<div <div
className="whitespace-pre" className="whitespace-pre-wrap"
style={{ backdropFilter: "blur(2px)", width, height }} style={{ backdropFilter: "blur(2px)", width, height }}
> >
<KittyProvider value={context}>{props.children}</KittyProvider> <KittyProvider value={context}>{props.children}</KittyProvider>

View File

@@ -14,5 +14,5 @@ export const NvimEditor = (props: { source: string | undefined }) => {
}); });
}, [props.source]); }, [props.source]);
return <div className="h-full">{loading ? "Loading..." : data}</div>; return <p>{loading ? "Loading..." : data}</p>;
}; };

View File

@@ -6,7 +6,7 @@ export const NvimStatusBar = (props: {
fileIcon?: string; fileIcon?: string;
fileName: string; fileName: string;
}) => ( }) => (
<div className="bg-[#29293c]"> <div className="select-none bg-[#29293c]">
<span className="text-[#272332]" style={{ background: props.labelColor }}> <span className="text-[#272332]" style={{ background: props.labelColor }}>
{` ${props.label} `} {` ${props.label} `}
</span> </span>

View File

@@ -10,7 +10,6 @@ import {
import { type Nvim } from ".."; import { type Nvim } from "..";
import { NvimTreeDirectory } from "./NvimTreeDirectory"; import { NvimTreeDirectory } from "./NvimTreeDirectory";
import { NvimTreeFile } from "./NvimTreeFile"; import { NvimTreeFile } from "./NvimTreeFile";
import { promiseHooks } from "v8";
const sortFiles = (files: Array<File | Directory>) => const sortFiles = (files: Array<File | Directory>) =>
files files

View File

@@ -1,15 +1,19 @@
import { useKitty } from "~/hooks/useKitty"; import { useKitty } from "~/hooks/useKitty";
import { CHAR_HEIGHT } from "../Kitty"; import { CHAR_HEIGHT, CHAR_WIDTH } from "../Kitty";
import { NvimEditor } from "./NvimEditor"; import { NvimEditor } from "./NvimEditor";
import { NvimInput } from "./NvimInput"; import { NvimInput } from "./NvimInput";
import { NvimStatusBar } from "./NvimStatusBar"; import { NvimStatusBar } from "./NvimStatusBar";
import { NvimTree } from "./NvimTree"; import { NvimTree } from "./NvimTree";
import { useState } from "react"; import { useState } from "react";
import { File } from "~/utils/types"; import { File, InnerKittyProps } from "~/utils/types";
export const Nvim = (_props: {}) => { export const Nvim = (_props: {}) => {
const kitty = useKitty(); const kitty = useKitty();
return kitty && <InnerNvimTree {...kitty} />;
};
const InnerNvimTree = (props: InnerKittyProps<typeof Nvim>) => {
const [activeFile, setActiveFile] = useState<{ const [activeFile, setActiveFile] = useState<{
name: string; name: string;
url: string; url: string;
@@ -32,31 +36,36 @@ export const Nvim = (_props: {}) => {
<div <div
className="grid h-full" className="grid h-full"
style={{ style={{
gridTemplateColumns: `0.4fr 2fr`, gridTemplateColumns: `minmax(${CHAR_WIDTH * 20}px, ${
Math.round(props.cols * 0.2) * CHAR_WIDTH
}px) 1fr`,
gridTemplateRows: `1fr ${CHAR_HEIGHT}px ${CHAR_HEIGHT}px`, gridTemplateRows: `1fr ${CHAR_HEIGHT}px ${CHAR_HEIGHT}px`,
}} }}
> >
{kitty && ( <div style={{ gridArea: "1 / 1 / 1 / 2" }}>
<> <NvimTree {...props} onOpen={handleOpenFile} />
<div style={{ gridArea: "1 / 1 / 1 / 2" }}> </div>
<NvimTree {...kitty} onOpen={handleOpenFile} /> <div
</div> className="overflow-y-auto break-all"
<div style={{ gridArea: "1 / 2 / 1 / 3", overflow: "scroll" }}> style={{
<NvimEditor source={activeFile?.url} /> gridArea: "1 / 2 / 1 / 3",
</div> overflowY: "auto",
<div style={{ gridArea: "2 / 1 / 2 / 3" }}> wordWrap: "break-word",
<NvimStatusBar }}
label=" NORMAL" >
labelColor="#7ea7ca" <NvimEditor source={activeFile?.url} />
fileIcon={activeFile?.icon} </div>
fileName={activeFile?.name ?? `NvimTree_1`} <div style={{ gridArea: "2 / 1 / 2 / 3" }}>
/> <NvimStatusBar
</div> label=" NORMAL"
<div style={{ gridArea: "3 / 1 / 3 / 3" }}> labelColor="#7ea7ca"
<NvimInput /> fileIcon={activeFile?.icon}
</div> fileName={activeFile?.name ?? `NvimTree_1`}
</> />
)} </div>
<div style={{ gridArea: "3 / 1 / 3 / 3" }}>
<NvimInput />
</div>
</div> </div>
); );
}; };