Skip to content

Commit

Permalink
Fix: Minor fixes (#207)
Browse files Browse the repository at this point in the history
* minor fix

* devmode for rich && clean up
  • Loading branch information
li-xin-yi authored Jan 23, 2023
1 parent 5725b19 commit b03e17c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
6 changes: 4 additions & 2 deletions ui/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ function verifyConsistency(nodes: Node[], nodesMap: YMap<Node>) {
);
return false;
}
if (Math.abs(node1.position.x - node2.position.x) > Number.EPSILON) {

// FIXME: Number.EPSILON is still too huge to compare two floats
if (Math.abs(node1.position.x - node2.position.x) > 0.01) {
console.error(
"node x are not the same",
node1.position.x,
node2.position.x
);
return false;
}
if (Math.abs(node1.position.y - node2.position.y) > Number.EPSILON) {
if (Math.abs(node1.position.y - node2.position.y) > 0.01) {
console.error(
"node y are not the same",
node1.position.y,
Expand Down
5 changes: 2 additions & 3 deletions ui/src/components/MyMonaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
const annotations = useStore(store, (state) => state.pods[id].annotations);
const showAnnotations = useStore(store, (state) => state.showAnnotations);
const scopedVars = useStore(store, (state) => state.scopedVars);
const updateView = useStore(store, (state) => state.updateView);

const value = getPod(id).content || "";
let lang = getPod(id).lang || "javascript";
Expand Down Expand Up @@ -461,9 +462,7 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
});
editor.onDidFocusEditorText(() => {
setPodFocus(id);

// FIXME: this is ugly, but useReactFlow.setNodes doesn't work to reset the selection
if (resetSelection()) nodesMap.set(id, nodesMap.get(id) as Node);
if (resetSelection()) updateView();
setCurrentEditor(id);
});
editor.onDidContentSizeChange(updateHeight);
Expand Down
42 changes: 20 additions & 22 deletions ui/src/components/nodes/Rich.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ import { GenIcon, IconBase } from "@remirror/react-components";
import { htmlToProsemirrorNode } from "remirror";
import { styled } from "@mui/material";

const selectionKeys = ["Enter", "Space", "Escape", "Tab"];

export interface SetHighlightButtonProps
extends Omit<
CommandButtonProps,
Expand Down Expand Up @@ -163,6 +161,7 @@ const MyEditor = ({
const setPodFocus = useStore(store, (state) => state.setPodFocus);
const setPodBlur = useStore(store, (state) => state.setPodBlur);
const resetSelection = useStore(store, (state) => state.resetSelection);
const updateView = useStore(store, (state) => state.updateView);
const isPodFocused = useStore(store, (state) => state.pods[id]?.focus);
const ref = useRef<HTMLDivElement>(null);
const { manager, state, setState } = useRemirror({
Expand Down Expand Up @@ -197,27 +196,12 @@ const MyEditor = ({
stringHandler: htmlToProsemirrorNode,
});

useEffect(() => {
const handler = (event: KeyboardEvent) => {
if (selectionKeys.indexOf(event.code) !== -1) {
// avoid to re-select this node
event.stopPropagation();
}
};
if (!isPodFocused || !ref.current) return;
ref.current?.addEventListener("keydown", handler);
return () => {
if (ref.current) ref.current.removeEventListener("keydown", handler);
};
}, [ref.current, isPodFocused]);

return (
<Box
className="remirror-theme"
onFocus={() => {
// FIXME: it's a dummy update in nodesMap to trigger the local update to clear all selection
if (resetSelection()) nodesMap.set(id, nodesMap.get(id) as Node);
setPodFocus(id);
if (resetSelection()) updateView();
}}
onBlur={() => {
setPodBlur(id);
Expand Down Expand Up @@ -301,6 +285,8 @@ export const RichNode = memo<Props>(function ({
id,
isConnectable,
selected,
xPos,
yPos,
}) {
const store = useContext(RepoContext);
if (!store) throw new Error("Missing BearContext.Provider in the tree");
Expand All @@ -311,10 +297,7 @@ export const RichNode = memo<Props>(function ({
const isGuest = useStore(store, (state) => state.role === "GUEST");
const width = useStore(store, (state) => state.pods[id]?.width);
const isPodFocused = useStore(store, (state) => state.pods[id]?.focus);
const index = useStore(
store,
(state) => state.pods[id]?.result?.count || " "
);
const devMode = useStore(store, (state) => state.devMode);
const inputRef = useRef<HTMLInputElement>(null);

const onResize = useCallback((e, data) => {
Expand Down Expand Up @@ -396,6 +379,21 @@ export const RichNode = memo<Props>(function ({
isConnectable={isConnectable}
/>
<Box className="custom-drag-handle">
{devMode && (
<Box
sx={{
position: "absolute",
top: "-48px",
bottom: "0px",
userSelect: "text",
cursor: "auto",
}}
className="nodrag"
>
{id} at ({Math.round(xPos)}, {Math.round(yPos)}, w: {pod.width}, h:{" "}
{pod.height})
</Box>
)}
<Box
sx={{
height: "1em",
Expand Down

0 comments on commit b03e17c

Please sign in to comment.