Advertisement
Guest User

4coder_keymap_repro.cpp

a guest
Aug 5th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #include "4coder_default_include.cpp"
  2.  
  3. enum keymaps {
  4.     keymap_works = 0,
  5.     keymap_doesnt = 1,
  6. };
  7.  
  8. CUSTOM_COMMAND_SIG(repro_unreachable) {
  9.     Query_Bar qb = {0};
  10.     qb.prompt = make_lit_string("/u/teryor ");
  11.     qb.string = make_lit_string("is an idiot");
  12.    
  13.     start_query_bar(app, &qb, 0);
  14.    
  15.     User_Input in = get_user_input(app, EventOnAnyKey, EventOnEsc);
  16. }
  17.  
  18. CUSTOM_COMMAND_SIG(repro_set_map_fail) {
  19.     View_Summary view = get_active_view(app, AccessAll);
  20.     Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessAll);
  21.    
  22.     // This should _NOT_ crash, as it fails silently
  23.     Assert(buffer_set_setting(app, &buffer, BufferSetting_MapID, keymap_doesnt));
  24.    
  25.     int32_t mapid;
  26.     buffer_get_setting(app, &buffer, BufferSetting_MapID, &mapid);
  27.    
  28.     // This _should_ crash
  29.     Assert(mapid == keymap_doesnt);
  30.     // Feel free to comment this out to verify that keymap_doesnt has indeed
  31.     // not been set, and that no commands can be run anymore.
  32. }
  33.  
  34. START_HOOK_SIG(repro_start) {
  35.     Buffer_Summary buffer = get_buffer_by_name(app, literal("*scratch*"), AccessAll);
  36.     buffer_set_setting(app, &buffer, BufferSetting_MapID, keymap_works);
  37.     return 0;
  38. }
  39.  
  40. extern "C" int32_t
  41. get_bindings(void *data, int32_t size){
  42.     Bind_Helper context_ = begin_bind_helper(data, size);
  43.     Bind_Helper *context = &context_;
  44.    
  45.     set_start_hook(context, repro_start);
  46.    
  47.     begin_map(context, keymap_works);
  48.     bind(context, ' ', MDFR_NONE, repro_set_map_fail);
  49.     end_map(context);
  50.    
  51.     // Keys can be bound to other maps without problem:
  52.     begin_map(context, keymap_doesnt);
  53.     bind(context, ' ', MDFR_NONE, repro_unreachable);
  54.     end_map(context);
  55.    
  56.     int32_t result = end_bind_helper(context);
  57.     return(result);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement