Delay in editing the text

Uint8 GEMEdit(struct GEMBOX B){
	if(!(B.State&3))return 0;
	int i,start=0,len=Len(B.Text),cpos=len,blen,bwlen=B.w/GPR.w;
	int p,start2=0,len2=LenUTF(B.Text,0,len),cpos2=len2;
	int bhlen=B.h/GPR.h,px=(B.w-bwlen*GPR.w)/2,py=(B.h-bhlen*GPR.h)/2;
	char*t=B.Text,*pt;
	static SDL_Rect CSRC={740,1,1,6};
	blen=bwlen;if(B.Type==12)blen*=bhlen;
	SDL_Event e;
	SDL_StartTextInput();
	while(!Quit && SDL_WaitEvent(&e)){
		Target(GEMScreen)
		switch(e.type){
		case SDL_MOUSEBUTTONDOWN:
			if(PointInRect(e.button.x,e.button.y,B.x,B.y,B.w,B.h)){
				p=(e.button.x-B.x)/GPR.w;if(B.Type==12)p+=(e.button.y-B.y)/GPR.h*bwlen;
				cpos2=p+start2;
				cpos=LenChr(B.Text,start,p)+start;}
			else Quit=2;
			break;
		case SDL_KEYDOWN:
			switch(e.key.keysym.sym){
			case SDLK_RETURN:
			case SDLK_KP_ENTER:Quit=3;break;
			case SDLK_LEFT:if(cpos){cpos-=(B.Text[cpos-1]&128)?2:1;cpos2--;}break;
			case SDLK_RIGHT:if(cpos<len){cpos+=(B.Text[cpos]&128)?2:1;cpos2++;}break;
			case SDLK_HOME:cpos=0;cpos2=0;break;
			case SDLK_END:cpos=len;cpos2=len2;break;
			case SDLK_DELETE:if(cpos<len){p=(B.Text[cpos]&128)?2:1;strcpy(&B.Text[cpos],&B.Text[cpos+p]);len-=p;len2--;}break;
			case SDLK_BACKSPACE:if(cpos){p=(B.Text[cpos-1]&128)?2:1;strcpy(&B.Text[cpos-p],&B.Text[cpos]);len-=p;cpos-=p;len2--;cpos2--;break;}
			case SDLK_v:if(SDL_GetModState()&KMOD_CTRL){pt=SDL_GetClipboardText();Let(B.Text,pt) SDL_free(pt);len=Len(B.Text);cpos=len;len2=LenUTF(B.Text,0,len);cpos2=len2;break;}
			case SDLK_x:if(SDL_GetModState()&KMOD_CTRL){SDL_SetClipboardText(B.Text);B.Text[0]=0;len=0;cpos=0;len2=0;cpos2=0;break;}
			case SDLK_c:if(SDL_GetModState()&KMOD_CTRL)SDL_SetClipboardText(B.Text);
			}break;
		case SDL_TEXTINPUT:
			p=Len(e.text.text);
			if(p+len<=STRLEN){
				for(i=len;i>=cpos;i--)B.Text[i+p]=B.Text[i];
				memmove(&B.Text[cpos],e.text.text,p);len+=p;cpos+=p;p=LenUTF(e.text.text,0,p);len2+=p;cpos2+=p;}
			break;
		case SDL_QUIT:Quit=1;
		}
	if(cpos2<blen/2)start=0;
	else if(len2-cpos2<=blen/2)start=len+LenChr(B.Text,len-1,-blen);
	else start=cpos+LenChr(B.Text,cpos-1,-blen/2);
	start2=cpos2-LenUTF(B.Text,start,cpos-1);
	B.Text=&B.Text[start]; GEMDrawBox(B); B.Text=t;
	p=cpos2-start2-1;
	if(B.Type==11) DST(B.x+px+(p+1)*GPR.w-1,B.y+py,2,GPR.h)
	else DST(B.x+px+p%bwlen*GPR.w+GPR.w-1,B.y+py+p/bwlen*GPR.h,2,GPR.h)
	GPColor(CCURSOR) PutImgRect(BASFont,CSRC,DST)
	if(GEMScreen)GEMShow else ShowPage
	}
  B.State&=~4;StopTextInput;Quit=Quit==1;return Quit;  
}

I have such an editor … Why is there a delay on Linux when I click the mouse to select the new cursor position? In Windows it works immediately …

Perhaps you could explain a bit more. Where is the delay?
It would be helpful if you could post a minimal reproducible example.

Are you running Linux inside a VM? It was a few years ago (and I was still using SDL 1.2) but I remember I used VirtualBox to install and test my program on different Linux distributions and there was some glitches with the mouse events when doing that. There was no problem when running Linux normally.

As I wrote. Edits the text, and when I click on it with the mouse - then the position of the cursor changes (and usually the text moves), it works with a delay.
Normal SparkyLinux, not VM.