From 8866bc889d7a0f9b712a3e49d6a16ddf56729233 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 24 Nov 2018 22:49:45 +0100 Subject: [PATCH] string editor now may restrict the available keys --- dialogs.cpp | 16 ++++++++++++---- hyper.h | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dialogs.cpp b/dialogs.cpp index dd5cfe8b..9622fa08 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -989,9 +989,15 @@ namespace dialog { edited_string = &s; editpos = isize(s); } + + string editchecker(int sym, int uni) { + if(uni >= 32 && uni < 127) return string("") + char(uni); + return ""; + } - bool handle_edit_string(int sym, int uni) { + bool handle_edit_string(int sym, int uni, function checker) { auto& es = *edited_string; + string u2; if(sym == SDLK_LEFT) editpos--; else if(sym == SDLK_RIGHT) editpos++; else if(uni == 8) { @@ -999,9 +1005,11 @@ namespace dialog { es.replace(editpos-1, 1, ""); editpos--; } - else if(uni >= 32 && uni < 128) { - es.insert(editpos, 1, uni); - editpos++; + else if((u2 = checker(sym, uni)) != "") { + for(char c: u2) { + es.insert(editpos, 1, c); + editpos ++; + } } else return false; return true; diff --git a/hyper.h b/hyper.h index ee4c9c8d..4f1afa7e 100644 --- a/hyper.h +++ b/hyper.h @@ -1842,7 +1842,8 @@ namespace dialog { string view_edited_string(); void start_editing(string& s); - bool handle_edit_string(int sym, int uni); + string editchecker(int sym, int uni); + bool handle_edit_string(int sym, int uni, function checker = editchecker); void edit_string(string& s, string title, string help); }