snaptoken / kilo-tutorial

build your own text editor
http://viewsourcecode.org/snaptoken/kilo
825 stars 80 forks source link

Why do we need put back the cursor at origin with EscH after implementing editorMoveCursor ? ? #38

Closed cassepipe closed 3 years ago

cassepipe commented 4 years ago

I am wondering why do we need put back the cursor at origin with the EscH command in the editorRefreshScreen() function after we have implemented editorMoveCursor() ? Calling snprintf(buf, sizeof(buf), "\x1b[%d;%dH", E.cy + 1, E.cx + 1); should be enough to reposition the cursor and yet it is not : I tried to erase abAppend(&ab, "\x1b[H", 3); from editorRefreshScreen() but then I noticed that the line which we happen to have the cursor on gets displayed on the first line. Do you know the reason beahind this strange behaviour ?

Thanks in advance.