about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-03-10 00:01:38 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-03-10 00:01:38 -0800
commit1485ee1be6d89d9e3cff6bc575d3aac9c3ef24ca (patch)
tree5976371e6414bba795f3c78c8d29adabfba62de9
parenta819afb0ae2bfe0e646dbbfedb60b7ce3d0ff5ac (diff)
downloadmu-1485ee1be6d89d9e3cff6bc575d3aac9c3ef24ca.tar.gz
3781
Support backspacing anywhere inside the search pattern in trace-browser.
-rw-r--r--100trace_browser.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/100trace_browser.cc b/100trace_browser.cc
index 024411b6..1cee716e 100644
--- a/100trace_browser.cc
+++ b/100trace_browser.cc
@@ -304,10 +304,20 @@ bool start_search_editor() {
     else if (key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2) {
       if (col > /*slash*/1) {
         --col;
-        tb_change_cell(col, bottom_screen_line, ' ', TB_WHITE, TB_BLACK);
+        // update pattern
+        pattern.erase(col-/*slash*/1, /*len*/1);
+        // update screen
+        if (col > SIZE(pattern)) {
+          tb_change_cell(col, bottom_screen_line, ' ', TB_WHITE, TB_BLACK);
+        }
+        else {
+          assert(col <= SIZE(pattern));
+          for (int x = col;  x < SIZE(pattern)+/*skip slash*/1;  ++x)
+            tb_change_cell(x, bottom_screen_line, pattern.at(x-/*slash*/1), TB_WHITE, TB_BLACK);
+          tb_change_cell(SIZE(pattern)+/*skip slash*/1, bottom_screen_line, ' ', TB_WHITE, TB_BLACK);
+        }
         tb_set_cursor(col, bottom_screen_line);
         tb_present();
-        pattern.erase(--pattern.end());
       }
     }
     else if (key < 128) {  // ascii only