Skip to content

Commit cee4600

Browse files
authored
fix: pod excution (#70)
* feat: add width ajustment * fix: Focused pod not executed #58 * Revert "feat: add width ajustment" This reverts commit 526557f.
1 parent 14f9258 commit cee4600

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

ui/src/components/Canvas.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
278278
const { setNodes } = useReactFlow();
279279
// const selected = useStore(store, (state) => state.selected);
280280
const setSelected = useStore(store, (state) => state.setSelected);
281+
const setCurrentEditor = useStore(store, (state) => state.setCurrentEditor);
281282
const getPod = useStore(store, (state) => state.getPod);
282283
const pod = getPod(id);
283284

@@ -409,6 +410,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
409410
}}
410411
onFocus={() => {
411412
setIsEditorBlur(false);
413+
setCurrentEditor(id);
412414
}}
413415
/>
414416
{showResult && (

ui/src/components/MyMonaco.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,15 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
329329
const setPodContent = useStore(store, (state) => state.setPodContent);
330330
const clearResults = useStore(store, (s) => s.clearResults);
331331
const wsRun = useStore(store, (state) => state.wsRun);
332+
332333
const value = getPod(id).content || "";
333334
let lang = getPod(id).lang || "javascript";
334335
const onChange = (value) => setPodContent({ id, content: value });
335336
const onRun = () => {
336-
clearResults(id);
337-
wsRun(id);
337+
// it's MonacoEditor's bug microsoft/monaco-editor#2947, it always triggered the last created instance
338+
const activeId = store.getState().currentEditor;
339+
clearResults(activeId);
340+
wsRun(activeId);
338341
};
339342

340343
if (lang === "racket") {

ui/src/lib/store.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ if (window.location.protocol === "http:") {
2727
}
2828
console.log("yjs server url: ", serverURL);
2929

30-
export const RepoContext = createContext<StoreApi<
31-
RepoSlice & RuntimeSlice
32-
> | null>(null);
30+
export const RepoContext =
31+
createContext<StoreApi<RepoSlice & RuntimeSlice> | null>(null);
3332

3433
// TODO use a selector to compute and retrieve the status
3534
// TODO this need to cooperate with syncing indicator
@@ -85,6 +84,8 @@ const initialState = {
8584
socketIntervalId: null,
8685
// keep different seletced info on each user themselves
8786
selected: null,
87+
// to fixed maco editor command bug
88+
currentEditor: null,
8889
//TODO: all presence information are now saved in clients map for future usage. create a modern UI to show those information from clients (e.g., online users)
8990
clients: new Map(),
9091
showLineNumbers: false,
@@ -180,6 +181,8 @@ export interface RepoSlice {
180181
setPodParent: ({ id, parent }: any) => void;
181182
selected: string | null;
182183
setSelected: (id: string | null) => void;
184+
currentEditor: string | null;
185+
setCurrentEditor: (id: string | null) => void;
183186
setUser: (user: any) => void;
184187
addClient: (clientId: any, name, color) => void;
185188
deleteClient: (clientId: any) => void;
@@ -238,6 +241,7 @@ const createRepoSlice: StateCreator<
238241
addError: (error) => set({ error }),
239242
clearError: () => set({ error: null }),
240243
setSelected: (id) => set({ selected: id }),
244+
setCurrentEditor: (id) => set({ currentEditor: id }),
241245
addPod: async (
242246
client,
243247
{ parent, index, anchor, shift, id, type, lang, x, y, width, height }

0 commit comments

Comments
 (0)