Skip to content

Commit

Permalink
Merge pull request #37 from NoteSpaceTeam/render
Browse files Browse the repository at this point in the history
Minor Changes
  • Loading branch information
R1c4rdCo5t4 committed Jun 24, 2024
2 parents a10b54f + d91b894 commit 0de312f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion code/client/src/contexts/workspace/WorkspaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function WorkspaceProvider({ children }: { children: React.ReactNode }) {
socket.disconnect();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [wid, services, socket]);
}, [wid]);

return (
<WorkspaceContext.Provider value={{ workspace, resources, operations: otherOperations }}>
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/domain/editor/connectors/markdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export function deleteAroundSelection(selection: Selection, amount: number, fugu
if (!nodeBefore || !nodeAfter) break;
idsToDelete.push(nodeBefore.id, nodeAfter.id);
}
return fugue.deleteLocalById(selection.start, ...idsToDelete);
return fugue.deleteLocalById(...idsToDelete);
}
6 changes: 4 additions & 2 deletions code/client/src/domain/editor/fugue/Fugue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export class Fugue {
let lineCounter = 0, // start.line
columnCounter = 0,
inBounds = false;
// const lineRootNode = this.tree.getLineRoot(start.line);

for (const node of this.tree.traverse(this.tree.root, returnDeleted)) {
// start condition
Expand Down Expand Up @@ -298,7 +297,10 @@ export class Fugue {
* @param cursor
*/
getNodeByCursor({ line, column }: Cursor): FugueNode | undefined {
if (column === 0) return this.tree.getLineRoot(line);
if (line === 0 && column === 0) return this.tree.root;
if (column === 0) {
return this.traverseBySeparator('\n', { line: line - 1, column: 1 }, false, true).next().value?.[0];
}
const start = { line, column: column - 1 };
const end = { line, column };
const iterator = this.traverseBySelection({ start, end });
Expand Down
20 changes: 0 additions & 20 deletions code/client/src/domain/editor/fugue/FugueTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ export class FugueTree<T> {
this._addNode(node);
}

/**
* Adds a line root node to the tree.
* @param line
* @param id
* @param parent
* @param side
* @param styles
*/
addLineRoot(line: number, id: Id, parent: Id, side: 'L' | 'R', styles?: InlineStyle[]) {
const node = treeNode(id, '\n', parent, side, 0, styles) as Node<T>;

this._root.value.splice(line, 0, node);

this._addNode(node);
}

/**
* Internal method to add a node to the tree.
* @param node
Expand Down Expand Up @@ -127,10 +111,6 @@ export class FugueTree<T> {
throw new Error('Unknown ID: ' + JSON.stringify(id));
}

getLineRoot(line: number): NodeType<T> {
return line === 0 ? this._root : this._root.value[line - 1];
}

setTree(nodes: Nodes<T>) {
this._nodes = new Map(Object.entries(nodes));
}
Expand Down
7 changes: 4 additions & 3 deletions code/client/src/ui/pages/document/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './Document.scss';

function Document() {
const communication = useCommunication();
const { http, socket } = communication;
const { socket } = communication;
const services = useDocumentService();
const fugue = useFugue();
const { publishError } = useError();
Expand All @@ -25,8 +25,8 @@ function Document() {
// redirect to workspace if document is deleted
connectors.service.on('deletedResource', rid => {
if (id === rid) {
navigate(`/workspaces/${wid}`);
publishError(Error('Document was deleted'));
navigate(`/workspaces/${wid}`);
}
});

Expand All @@ -46,7 +46,8 @@ function Document() {
return () => {
socket.emit('leaveDocument');
};
}, [fugue, id, http, socket, publishError, services, setTitle, navigate]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);

if (!loaded) return null;
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Editor({ title, connectors, fugue }: EditorProps) {
connectors.input,
connectors.markdown
);
useEvents(editor, connectors.service, syncEditor);
useEvents(connectors.service, syncEditor);

return (
<div className="editor">
Expand Down

0 comments on commit 0de312f

Please sign in to comment.