diff options
author | Kevin Ballard <kevin@sb.org> | 2014-09-22 21:04:06 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-09-22 21:04:06 -0700 |
commit | 0a3f2205729d13897e86efe2b7d9452000117605 (patch) | |
tree | d90226dfbc496312cfa1d4de2b39c503d4ed905e /input.cpp | |
parent | 5eee7d17f610f58e4e797529f64751c18e237559 (diff) |
Rework mode handling of `bind`
Binds with the same sequence in multiple modes was not working right.
Fix up the implementation to propagate modes everywhere as necessary.
This means that `bind` will properly list distinct binds with the same
sequence, and `bind -e` will take mode into account properly as well.
Note that `bind -e seq` now assumes the bind is in the default bind
mode, whereas before it would erase the first binding with that sequence
regardless of mode.
`bind -e -a` still erases all binds in all modes, though `bind -M mode
-e -a` still only erases all binds in the selected mode.
Diffstat (limited to 'input.cpp')
-rw-r--r-- | input.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
@@ -772,59 +772,53 @@ wint_t input_readch(bool allow_commands) } } -wcstring_list_t input_mapping_get_names() +std::vector<input_mapping_name_t> input_mapping_get_names() { // Sort the mappings by the user specification order, so we can return them in the same order that the user specified them in std::vector<input_mapping_t> local_list = mapping_list; std::sort(local_list.begin(), local_list.end(), specification_order_is_less_than); - wcstring_list_t result; + std::vector<input_mapping_name_t> result; result.reserve(local_list.size()); for (size_t i=0; i<local_list.size(); i++) { const input_mapping_t &m = local_list.at(i); - result.push_back(m.seq); + result.push_back((input_mapping_name_t){m.seq, m.mode}); } return result; } -bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode) +bool input_mapping_erase(const wcstring &sequence, const wcstring &mode) { ASSERT_IS_MAIN_THREAD(); bool result = false; - size_t i, sz = mapping_list.size(); - for (i=0; i<sz; i++) + for (std::vector<input_mapping_t>::const_iterator it = mapping_list.begin(), end = mapping_list.end(); + it != end; + ++it) { - const input_mapping_t &m = mapping_list.at(i); - if (sequence == m.seq && (mode == NULL || mode == m.mode)) + if (sequence == it->seq && mode == it->mode) { - if (i != (sz-1)) - { - mapping_list[i] = mapping_list[sz-1]; - } - mapping_list.pop_back(); + mapping_list.erase(it); result = true; break; - } } return result; } -bool input_mapping_get(const wcstring &sequence, wcstring_list_t *out_cmds, wcstring *out_mode, wcstring *out_sets_mode) +bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds, wcstring *out_sets_mode) { bool result = false; - size_t sz = mapping_list.size(); - for (size_t i=0; i<sz; i++) + for (std::vector<input_mapping_t>::const_iterator it = mapping_list.begin(), end = mapping_list.end(); + it != end; + ++it) { - const input_mapping_t &m = mapping_list.at(i); - if (sequence == m.seq) + if (sequence == it->seq && mode == it->mode) { - *out_cmds = m.commands; - *out_mode = m.mode; - *out_sets_mode = m.sets_mode; + *out_cmds = it->commands; + *out_sets_mode = it->sets_mode; result = true; break; } |