aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2018-11-17 18:50:25 +1000
committerinmarket <andrewh@inmarket.com.au>2018-11-17 18:50:25 +1000
commit509fc7501e7bd30b1b314fc0d4838d7cdf6ac621 (patch)
tree28c8a230d97fe7012127a83cfcd39cb18572221c
parentd528fb218d2773c051098cd44cb6eb0eb0732be0 (diff)
downloaduGFX-509fc7501e7bd30b1b314fc0d4838d7cdf6ac621.tar.gz
uGFX-509fc7501e7bd30b1b314fc0d4838d7cdf6ac621.tar.bz2
uGFX-509fc7501e7bd30b1b314fc0d4838d7cdf6ac621.zip
Textedit fix - as per Neon1
-rw-r--r--src/gwin/gwin_textedit.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c
index 3a2626d0..68c333c9 100644
--- a/src/gwin/gwin_textedit.c
+++ b/src/gwin/gwin_textedit.c
@@ -34,6 +34,8 @@ static void TextEditRemoveChar(GHandle gh) {
sz = strlen(gh2obj->w.text);
pos = gh2obj->cursorPos;
+ if (pos > sz)
+ pos = gh2obj->cursorPos = sz;
q = gh2obj->w.text+pos;
if (!(gh->flags & GWIN_FLG_ALLOCTXT)) {
@@ -62,6 +64,8 @@ static gBool TextEditAddChars(GHandle gh, unsigned cnt) {
// Get the size of the text buffer
sz = strlen(gh2obj->w.text)+1;
pos = gh2obj->cursorPos;
+ if (pos >= sz)
+ pos = gh2obj->cursorPos = sz-1;
if (!(gh->flags & GWIN_FLG_ALLOCTXT)) {
if (!(p = gfxAlloc(sz+cnt)))
@@ -185,9 +189,16 @@ GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* wt, GWidgetInit* pInit
#if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || GWIN_NEED_KEYBOARD
void gwinTextEditSendSpecialKey(GHandle gh, gU8 key) {
- // Is it a valid handle?
- if (gh->vmt != (gwinVMT*)&texteditVMT)
- return;
+ unsigned sz;
+
+ // Is it a valid handle?
+ if (gh->vmt != (gwinVMT*)&texteditVMT)
+ return;
+
+ // Check that cursor position is within buffer (in case text has been changed)
+ sz = strlen(gh2obj->w.text);
+ if (gh2obj->cursorPos > sz)
+ gh2obj->cursorPos = sz;
// Arrow keys to move the cursor
switch (key) {
@@ -209,7 +220,7 @@ GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* wt, GWidgetInit* pInit
case GKEY_END:
if (!gh2obj->w.text[gh2obj->cursorPos])
return;
- gh2obj->cursorPos = strlen(gh2obj->w.text);
+ gh2obj->cursorPos = sz;
break;
default:
return;