SDL: delete key for editing.
authorTimo Korvola <tkorvola@iki.fi>
Sun, 8 Apr 2018 19:20:00 +0000 (22:20 +0300)
committerTimo Korvola <tkorvola@iki.fi>
Sun, 8 Apr 2018 19:20:00 +0000 (22:20 +0300)
src/sdl/sf_frotz.h
src/sdl/sf_video.c

index d95cb229b6065037a1d81917d5c1649f82464ccb..a2c84270ec0751f0054b0c34ba6370d0fb6a1759 100644 (file)
@@ -253,6 +253,7 @@ void sf_FinishProfile(void);
 #define VK_INS 0x17
 #define VK_PAGE_UP 0x18
 #define VK_PAGE_DOWN 0x19
+#define VK_DEL 0x100
 
 // for AIFF resampling
 
index 3980da19ec3deb7fa8138e9d5ef6c4ba99653227..34f51b7b1c0b7327430c830373801a475845e685 100644 (file)
@@ -652,6 +652,7 @@ static zword goodzkey( SDL_Event *e, int allowed)
            numAltQ = 0;
         switch (e->key.keysym.sym) {
        case SDLK_INSERT:       return (allowed ? VK_INS : 0);
+       case SDLK_DELETE:       return (allowed ? VK_DEL : 0);
        case SDLK_BACKSPACE:    return ZC_BACKSPACE;
        case SDLK_ESCAPE:       return ZC_ESCAPE;
        case SDLK_RETURN:       return ZC_RETURN;
@@ -848,11 +849,20 @@ zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued)
                 case ZC_BACKSPACE:
                     // Delete the character to the left of the cursor
                     if (pos > 0) {
-                        memmove(buf+pos-1,buf+pos,sizeof(zword)*(mywcslen(buf)-pos+1));
+                        memmove(buf + pos - 1, buf + pos,
+                                sizeof(zword) * (mywcslen(buf) - pos + 1));
                         pos--;
                         sf_DrawInput(buf,pos,ptx,pty,width,true);
                     }
                     continue;
+                case VK_DEL:
+                    // Delete the character to the right of the cursor
+                    if (pos < mywcslen(buf)) {
+                        memmove(buf + pos, buf + pos + 1,
+                                sizeof(zword) * (mywcslen(buf) - pos));
+                        sf_DrawInput(buf,pos,ptx,pty,width,true);
+                    }
+                    continue;
                 case ZC_ESCAPE:         /* Delete whole line */
                     pos = 0;
                     buf[0] = '\0';