Skip to content

I'm developing a codeshare app with monaco. how can i get keyboard event or how can i control when to emit? #3646

Answered by amRohitKumar
cornorghost asked this question in Q&A
Discussion options

You must be logged in to vote

@cornorghost
Hey, I found the solution. You can keep some kind of variable to resolve this conflict.
I'm using this with Next.js, so I used the useRef hook.
Here is my code:

const isSocket = useRef(false);
// socket listener
socket.on("code-change-received", (changeEvent) => {
      isSocket.current = true;
      editorRef.current?.executeEdits("other-user", [
          changeEvent.range,
          text: changeEvent.text,
          forceMoveMarkers: true,
        },
      ]);
    });
// onChange function on editor
function handleEditorChange(value, event) {
    if (!isSocket.current) {
      console.log("here is the current model value:", event);
      socket.emit("code-change", event.cha…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by hediet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
2 participants
Converted from issue

This discussion was converted from issue #2752 on March 03, 2023 13:23.