cursor&focus bug

I’m a beginner developer.

I can not speak English very well

So I’ve attached a video

I want to create a program that shares code in real time via web-socket.

However, every time through the keyup function, textarea sends the code using getValue, setValue like the video.

But whenever the code is modified, the cursor goes to the front of the textarea.

I need your help desperately.Thank you