Skip to content

Commit

Permalink
Handle null state in cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
choidabom committed Aug 26, 2024
1 parent ec7daf2 commit 5dd28ba
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions frontend/src/components/headers/UserPresenceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function UserPresenceList(props: UserPresenceListProps) {

const handleScrollToUserLocation = (presence: Presence) => {
const cursor = presence.presence.cursor;
if (cursor === null) return;

editorStore.cmView?.dispatch({
effects: EditorView.scrollIntoView(cursor[0], {
y: "center",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useYorkieDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useYorkieDocument = (
name: presenceName,
color: Color(randomColor()).fade(0.15).toString(),
selection: null,
cursor: [0, 0],
cursor: null,
},
});
},
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/utils/yorkie/remoteSelection.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as cmView from "@codemirror/view";

import * as cmState from "@codemirror/state";
import * as cmView from "@codemirror/view";
import * as dom from "lib0/dom";
import * as pair from "lib0/pair";
import _ from "lodash";
import * as yorkie from "yorkie-js-sdk";

import {
YorkieSyncConfig,
YorkieCodeMirrorDocType,
YorkieCodeMirrorPresenceType,
YorkieSyncConfig,
yorkieSyncFacet,
} from "./yorkieSync.js";
import _ from "lodash";

export const yorkieRemoteSelectionsTheme = cmView.EditorView.baseTheme({
".cm-ySelection": {},
Expand Down Expand Up @@ -162,6 +160,7 @@ export class YorkieRemoteSelectionsPluginValue {
} else if (presence.get("selection")) {
presence.set({
selection: null,
cursor: null,
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/yorkie/yorkieSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type YorkieCodeMirrorPresenceType = {
color: string;
name: string;
selection: yorkie.TextPosStructRange | null;
cursor: [number, number];
cursor: [number, number] | null;
};

export class YorkieSyncConfig<
Expand Down

0 comments on commit 5dd28ba

Please sign in to comment.