From 2c99e8c6869c8786e7c2ce95f2af82acf0831141 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 14 Aug 2015 18:53:05 +0200 Subject: [PATCH] Adding handler for the DELETE button to the TextEdit widget --- src/gwin/gwin_textedit.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c index 999a91dd..8f5cb8dd 100644 --- a/src/gwin/gwin_textedit.c +++ b/src/gwin/gwin_textedit.c @@ -86,7 +86,7 @@ static void _shiftTextRight(char* buffer, size_t bufferSize, size_t index, char // Parse the key press else if (pke->bytecount >= 1) { - // Check backspace + // Is it backspace? if (pke->c[0] == GKEY_BACKSPACE) { if (gw2obj->cursorPos == 0) { return; @@ -94,6 +94,15 @@ static void _shiftTextRight(char* buffer, size_t bufferSize, size_t index, char _shiftTextLeft(gw2obj->textBuffer, gw2obj->bufferSize, gw2obj->cursorPos--); } + // Is it delete? + else if (pke->c[0] == GKEY_DEL) { + // Check whether there is a character on the right side of the cursor + if (gw2obj->textBuffer[gw2obj->cursorPos] == '\0') { + return; + } + _shiftTextLeft(gw2obj->textBuffer, gw2obj->bufferSize, gw2obj->cursorPos+1); + } + // Add a new character else { // Shift everything right from the cursor by one character. This includes the '\0'. Then inser the new character.