commit 2f30a4b356e9cf8e60802c9f885a7bf71da20681 parent 668afb124c43e5bbe3a72918b0a36485d1ed2241 Author: Jan P. Pasierb <me@janpasierb.com> Date: Sun, 17 Jul 2022 21:24:12 +0100 Fixed replace code and extracted it into its own method Diffstat:
M | input.c | | | 18 | +++++++++++++++--- |
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/input.c b/input.c @@ -42,6 +42,20 @@ void processClusterKey(char c) { E.clusterkey = '\0'; } +void editorReplaceChar(char c) { + E.isreplace = 0; + erow* row = (E.cy >= E.numrows) ? NULL : &E.row[E.cy]; + + if(row && row->size == 0) + return; + + editorDelChar(); + editorInsertChar(c); + + if(row && E.cx >= row->size - 1) + E.cx--; +} + char* editorPrompt(char* prompt, void (*callback)(char*, int)) { size_t bufsize = 128; char* buf = malloc(bufsize); @@ -162,9 +176,7 @@ void editorProcessKeypress() { if(E.clusterkey != '\0') { processClusterKey(c); } else if (E.isreplace) { - E.isreplace = 0; - editorDelChar(); - editorInsertChar(c); + editorReplaceChar(c); } else { switch(c) { case QUIT: