Skip to content

Commit

Permalink
Code Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Mar 28, 2024
1 parent 2b6700c commit d8709e6
Show file tree
Hide file tree
Showing 39 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion code/client/dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['./workbox-fda11f75'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.965t3hopnrg"
"revision": "0.jepaoi887g"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
1 change: 1 addition & 0 deletions code/client/src/editor/hooks/useEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function useEvents(fugue: Fugue, onDone: () => void) {
switch (operation.type) {
case 'insert':
fugue.insertRemote(operation);
// TODO: update the style of the added node in slate
break;
case 'delete':
fugue.deleteRemote(operation);
Expand Down
24 changes: 0 additions & 24 deletions code/client/src/editor/slate.js/plugins/normalize/withNormalize.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Toolbar from '@editor/slate.js/toolbar/Toolbar';
import { withHistory } from 'slate-history';
import useEditor from '@editor/slate.js/hooks/useEditor';
import { withMarkdown } from '@editor/slate.js/plugins/markdown/withMarkdown';
import { withNormalize } from './plugins/normalize/withNormalize';
import { toSlate } from '@editor/slate.js/utils/toSlate';

const initialValue = [
Expand All @@ -19,7 +18,7 @@ const initialValue = [
];

function SlateEditor() {
const editor = useEditor(withHistory, withReact, withMarkdown, withNormalize);
const editor = useEditor(withHistory, withReact, withMarkdown);
const fugue = useFugue();
const { onKeyDown, onPaste, onCut } = useInputHandlers(editor, fugue);
const { renderElement, renderLeaf } = useRenderers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function useInputHandlers(editor: Editor, fugue: Fugue) {

const selection = getSelection(editor);
const { start, end } = selection;

switch (e.key) {
case 'Enter':
fugue.insertLocal(start, insertNode('\n', []));
Expand All @@ -37,10 +36,9 @@ function useInputHandlers(editor: Editor, fugue: Fugue) {
default: {
if (e.key.length !== 1) break;
if (selection.start.column !== selection.end.column) {
// replace selection
fugue.deleteLocal(selection);
fugue.deleteLocal(selection); // replace selection
}
const previousNode = fugue.getNodeByCursor({ line: start.line, column: start.column - 1 });
const previousNode = fugue.getNodeByCursor(start);
const styles = previousNode?.styles || [];
fugue.insertLocal(start, insertNode(e.key, styles));
break;
Expand Down Expand Up @@ -71,11 +69,20 @@ function useInputHandlers(editor: Editor, fugue: Fugue) {
}

function shortcutHandler(event: React.KeyboardEvent<HTMLDivElement>) {
const mark = hotkeys[event.key];
CustomEditor.toggleMark(editor, mark, fugue);
switch (event.key) {
case 'z':
onUndo();
break;
case 'y':
onRedo();
break;
default: {
const mark = hotkeys[event.key];
CustomEditor.toggleMark(editor, mark, fugue);
}
}
}

return { onKeyDown, onPaste, onCut, onUndo, onRedo };
return { onKeyDown, onPaste, onCut };
}

export default useInputHandlers;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function onConnection(service: DocumentService, events: Record<string, SocketHan
Object.entries(events).forEach(([event, handler]) => {
socket.on(event, data => {
try {
// console.log(event);
console.log(event, data);
handler(socket, data);
} catch (e) {
socket.emit('error');
Expand Down

0 comments on commit d8709e6

Please sign in to comment.