Skip to content

Fix: Minor fixes #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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