diff --git a/.all-contributorsrc b/.all-contributorsrc deleted file mode 100644 index 8717657..0000000 --- a/.all-contributorsrc +++ /dev/null @@ -1,28 +0,0 @@ -{ - "projectName": "Jest tools", - "projectOwner": "Raathigesh", - "repoType": "github", - "repoHost": "https://github.com", - "files": [ - "README.md" - ], - "imageSize": 100, - "commit": false, - "commitConvention": "none", - "contributors": [ - { - "login": "Raathigesh", - "name": "Raathi Kugarajan", - "avatar_url": "https://avatars.githubusercontent.com/u/3108160?v=4", - "profile": "https://github.com/Raathigesh", - "contributions": [ - "code", - "doc", - "ideas", - "infra", - "maintenance" - ] - } - ], - "contributorsPerLine": 7 -} diff --git a/README.md b/README.md index 1095111..4bf5d06 100644 --- a/README.md +++ b/README.md @@ -1,21 +1 @@ Paper - -### Contributors - -Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): - - - - - - - - -

Raathi Kugarajan

💻 📖 🤔 🚇 🚧
- - - - - - -This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! diff --git a/src/extension/api/index.ts b/src/extension/api/index.ts index 67f285c..59f63e0 100644 --- a/src/extension/api/index.ts +++ b/src/extension/api/index.ts @@ -108,6 +108,34 @@ export async function startApiServer( }); }); + // View specific endpoints + app.get('/activeFilePath', (req, res) => { + res.json({ + activeFilePath: vscode.window.activeTextEditor?.document.fileName, + }); + }); + + app.get('/getSelection', (req, res) => { + if (vscode.window.activeTextEditor?.selection.start) { + const selectionRange = new vscode.Range( + vscode.window.activeTextEditor?.selection.start, + vscode.window.activeTextEditor?.selection.end + ); + const text = vscode.window.activeTextEditor?.document.getText( + selectionRange + ); + + const fullTxt = `${text}|${vscode.window.activeTextEditor?.document.fileName}|${selectionRange.start.line}|${selectionRange.start.character}|${selectionRange.end.line}|${selectionRange.end.character}`; + res.json({ + selection: fullTxt, + }); + } + + res.json({ + selection: null, + }); + }); + return new Promise((resolve, reject) => { app.listen(port, () => { const url = `http://localhost:${port}`; diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 705b24a..65da343 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -82,6 +82,7 @@ function App() { { getContent(); }} diff --git a/src/ui/CreateDoc.tsx b/src/ui/CreateDoc.tsx index a482cdf..b071c2e 100644 --- a/src/ui/CreateDoc.tsx +++ b/src/ui/CreateDoc.tsx @@ -19,10 +19,14 @@ import { ClientDoc } from './types'; const API_URL = `http://localhost:${(window as any).port || '4545'}`; interface Props { + activeDoc: ClientDoc | null; onActiveDocumentChange: () => void; } -export default function CreateDoc({ onActiveDocumentChange }: Props) { +export default function CreateDoc({ + activeDoc, + onActiveDocumentChange, +}: Props) { const [docs, setDocs] = useState([]); const [docName, setDocName] = useState(''); @@ -46,10 +50,6 @@ export default function CreateDoc({ onActiveDocumentChange }: Props) { onActiveDocumentChange(); }; - useEffect(() => { - getDocs(); - }, []); - const createDoc = async (name: string) => { const response = await fetch(`${API_URL}/create`, { method: 'POST', @@ -66,7 +66,7 @@ export default function CreateDoc({ onActiveDocumentChange }: Props) { }; return ( - + getDocs()}> - - - - - - - - - - + } + /> + + { + const focusResult = editor.chain().focus(); + (focusResult as any).toggleTreeView().run(); + }} + icon={} + /> )} diff --git a/src/ui/EditorFloatingButton.tsx b/src/ui/EditorFloatingButton.tsx new file mode 100644 index 0000000..771f69d --- /dev/null +++ b/src/ui/EditorFloatingButton.tsx @@ -0,0 +1,24 @@ +import { Tooltip, Button } from '@chakra-ui/react'; +import React from 'react'; + +interface Props { + onClick: () => void; + tooltip: string; + icon: any; +} + +export function EditorFloatingButton({ onClick, tooltip, icon }: Props) { + return ( + + + + ); +} diff --git a/src/ui/editor-views/file-bookmark/Component.tsx b/src/ui/editor-views/file-bookmark/Component.tsx new file mode 100644 index 0000000..7b1ddc7 --- /dev/null +++ b/src/ui/editor-views/file-bookmark/Component.tsx @@ -0,0 +1,87 @@ +import React, { useEffect, useState } from 'react'; +import { NodeViewWrapper } from '@tiptap/react'; +import { + Input, + Box, + IconButton, + Flex, + Modal, + ModalOverlay, + ModalContent, + ModalHeader, + ModalCloseButton, + ModalBody, + ModalFooter, + Button, +} from '@chakra-ui/react'; +import { Edit, Check, Edit2, Trash } from 'react-feather'; +import './styles.css'; + +const API_URL = `http://localhost:${(window as any).port || '4545'}`; + +export default (props: any) => { + const setPath = (bookmark: string) => { + props.updateAttributes({ + path: bookmark, + }); + }; + + const getActivePath = async () => { + if (props.node.attrs.path === '') { + const response = await fetch(`${API_URL}/activeFilePath`); + const data = await response.json(); + if (data.activeFilePath) { + setPath(data.activeFilePath); + } + } + }; + + useEffect(() => { + getActivePath(); + }, []); + + const openFile = (path: string) => { + fetch(`${API_URL}/open-file`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + filePath: path, + }), + }); + }; + + return ( + + openFile(props.node.attrs.path)} + > + {props.node.attrs.path} + { + e.stopPropagation(); + props.deleteNode(); + }} + marginLeft="5px" + height="100%" + alignItems="center" + > + + + + + ); +}; diff --git a/src/ui/editor-views/symbol-bookmark/index.tsx b/src/ui/editor-views/file-bookmark/index.tsx similarity index 100% rename from src/ui/editor-views/symbol-bookmark/index.tsx rename to src/ui/editor-views/file-bookmark/index.tsx diff --git a/src/ui/editor-views/range-bookmark/styles.css b/src/ui/editor-views/file-bookmark/styles.css similarity index 100% rename from src/ui/editor-views/range-bookmark/styles.css rename to src/ui/editor-views/file-bookmark/styles.css diff --git a/src/ui/editor-views/range-bookmark/Component.tsx b/src/ui/editor-views/range-bookmark/Component.tsx deleted file mode 100644 index bc44f97..0000000 --- a/src/ui/editor-views/range-bookmark/Component.tsx +++ /dev/null @@ -1,145 +0,0 @@ -import React, { useState } from 'react'; -import { NodeViewWrapper } from '@tiptap/react'; -import { - Input, - Box, - IconButton, - Flex, - Modal, - ModalOverlay, - ModalContent, - ModalHeader, - ModalBody, - ModalFooter, - Button, -} from '@chakra-ui/react'; -import { Edit, Check } from 'react-feather'; -import './styles.css'; - -const API_URL = `http://localhost:${(window as any).port || '4545'}`; - -export default (props: any) => { - const [isInEdit, setIsInEdit] = useState(props.node.attrs.path === ''); - const setPath = (bookmark: string) => { - props.updateAttributes({ - path: bookmark, - }); - }; - - const [ - name, - path, - startLine, - startChar, - endLine, - endChar, - ] = props.node.attrs.path.split('|'); - - const openFile = (path: string) => { - fetch(`${API_URL}/open-file`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - filePath: path, - selection: { - start: { - line: Number(startLine), - column: Number(startChar), - }, - end: { - line: Number(endLine), - column: Number(endChar), - }, - }, - }), - }); - }; - - return ( - - setIsInEdit(false)}> - - - - Add range bookmark - - - setPath(e.target.value)} - value={props.node.attrs.path} - onBlur={() => setIsInEdit(false)} - size="sm" - /> - - - - - - - - - - {!isInEdit && ( - openFile(path)} - color="#090909" - > - {name} - { - e.stopPropagation(); - setIsInEdit(true); - }} - marginLeft="5px" - height="100%" - alignItems="center" - > - - - - )} - - ); -}; diff --git a/src/ui/editor-views/selection-bookmark/Component.tsx b/src/ui/editor-views/selection-bookmark/Component.tsx new file mode 100644 index 0000000..7c14f05 --- /dev/null +++ b/src/ui/editor-views/selection-bookmark/Component.tsx @@ -0,0 +1,105 @@ +import React, { useEffect, useState } from 'react'; +import { NodeViewWrapper } from '@tiptap/react'; +import { + Input, + Box, + IconButton, + Flex, + Modal, + ModalOverlay, + ModalContent, + ModalHeader, + ModalBody, + ModalFooter, + Button, +} from '@chakra-ui/react'; +import { Edit, Check, Trash } from 'react-feather'; +import './styles.css'; + +const API_URL = `http://localhost:${(window as any).port || '4545'}`; + +export default (props: any) => { + const setPath = (bookmark: string) => { + props.updateAttributes({ + path: bookmark, + }); + }; + + const getActivePath = async () => { + if (props.node.attrs.path === '') { + const response = await fetch(`${API_URL}/getSelection`); + const data = await response.json(); + if (data.selection) { + setPath(data.selection); + } + } + }; + + useEffect(() => { + getActivePath(); + }, []); + + const [ + name, + path, + startLine, + startChar, + endLine, + endChar, + ] = props.node.attrs.path.split('|'); + + const openFile = (path: string) => { + fetch(`${API_URL}/open-file`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + filePath: path, + selection: { + start: { + line: Number(startLine), + column: Number(startChar), + }, + end: { + line: Number(endLine), + column: Number(endChar), + }, + }, + }), + }); + }; + + return ( + + openFile(path)} + > + {name} + { + e.stopPropagation(); + props.deleteNode(); + }} + marginLeft="5px" + height="100%" + alignItems="center" + > + + + + + ); +}; diff --git a/src/ui/editor-views/range-bookmark/index.tsx b/src/ui/editor-views/selection-bookmark/index.tsx similarity index 100% rename from src/ui/editor-views/range-bookmark/index.tsx rename to src/ui/editor-views/selection-bookmark/index.tsx diff --git a/src/ui/editor-views/symbol-bookmark/styles.css b/src/ui/editor-views/selection-bookmark/styles.css similarity index 100% rename from src/ui/editor-views/symbol-bookmark/styles.css rename to src/ui/editor-views/selection-bookmark/styles.css diff --git a/src/ui/editor-views/symbol-bookmark/Component.tsx b/src/ui/editor-views/symbol-bookmark/Component.tsx deleted file mode 100644 index 26cb82b..0000000 --- a/src/ui/editor-views/symbol-bookmark/Component.tsx +++ /dev/null @@ -1,123 +0,0 @@ -import React, { useState } from 'react'; -import { NodeViewWrapper } from '@tiptap/react'; -import { - Input, - Box, - IconButton, - Flex, - Modal, - ModalOverlay, - ModalContent, - ModalHeader, - ModalCloseButton, - ModalBody, - ModalFooter, - Button, -} from '@chakra-ui/react'; -import { Edit, Check, Edit2 } from 'react-feather'; -import './styles.css'; - -const API_URL = `http://localhost:${(window as any).port || '4545'}`; - -export default (props: any) => { - const [isInEdit, setIsInEdit] = useState(props.node.attrs.path === ''); - const setPath = (bookmark: string) => { - props.updateAttributes({ - path: bookmark, - }); - }; - - const openFile = (path: string) => { - fetch(`${API_URL}/open-file`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - filePath: path, - }), - }); - }; - - return ( - - setIsInEdit(false)}> - - - - Add file bookmark - - - setPath(e.target.value)} - value={props.node.attrs.path} - onBlur={() => setIsInEdit(false)} - size="sm" - /> - - - - - - - - - openFile(props.node.attrs.path)} - > - {props.node.attrs.path} - { - e.stopPropagation(); - setIsInEdit(true); - }} - marginLeft="5px" - height="100%" - alignItems="center" - > - - - - - ); -};