mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Changes to bind_mode implementation based on code review and merge
errors
This commit is contained in:
parent
d4fafeb6d6
commit
bd895aa76c
5 changed files with 88 additions and 98 deletions
17
builtin.cpp
17
builtin.cpp
|
@ -404,8 +404,7 @@ int builtin_test(parser_t &parser, wchar_t **argv);
|
|||
static void builtin_bind_list(const wchar_t *bind_mode)
|
||||
{
|
||||
size_t i;
|
||||
wcstring_list_t lst;
|
||||
input_mapping_get_names(lst);
|
||||
const wcstring_list_t lst = input_mapping_get_names();
|
||||
|
||||
for (i=0; i<lst.size(); i++)
|
||||
{
|
||||
|
@ -415,9 +414,12 @@ static void builtin_bind_list(const wchar_t *bind_mode)
|
|||
wcstring mode;
|
||||
wcstring sets_mode;
|
||||
|
||||
input_mapping_get(seq, ecmds, mode, sets_mode);
|
||||
if (! input_mapping_get(seq, &ecmds, &mode, &sets_mode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(bind_mode != NULL && wcscmp(mode.c_str(), bind_mode))
|
||||
if (bind_mode != NULL && bind_mode != mode)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -542,11 +544,8 @@ static void builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode)
|
|||
{
|
||||
if (all)
|
||||
{
|
||||
size_t i;
|
||||
wcstring_list_t lst;
|
||||
input_mapping_get_names(lst);
|
||||
|
||||
for (i=0; i<lst.size(); i++)
|
||||
const wcstring_list_t lst = input_mapping_get_names();
|
||||
for (size_t i=0; i<lst.size(); i++)
|
||||
{
|
||||
input_mapping_erase(lst.at(i).c_str(), mode);
|
||||
}
|
||||
|
|
73
input.cpp
73
input.cpp
|
@ -71,7 +71,7 @@
|
|||
struct input_mapping_t
|
||||
{
|
||||
wcstring seq; /**< Character sequence which generates this event */
|
||||
std::vector<wcstring> commands; /**< commands that should be evaluated by this mapping */
|
||||
wcstring_list_t commands; /**< commands that should be evaluated by this mapping */
|
||||
|
||||
/* We wish to preserve the user-specified order. This is just an incrementing value. */
|
||||
unsigned int specification_order;
|
||||
|
@ -285,32 +285,25 @@ static bool is_init = false;
|
|||
*/
|
||||
static void input_terminfo_init();
|
||||
|
||||
wchar_t input_function_args[MAX_INPUT_FUNCTION_ARGS];
|
||||
bool input_function_status;
|
||||
int input_function_args_index = 0;
|
||||
static wchar_t input_function_args[MAX_INPUT_FUNCTION_ARGS];
|
||||
static bool input_function_status;
|
||||
static int input_function_args_index = 0;
|
||||
|
||||
/**
|
||||
Return the current bind mode
|
||||
*/
|
||||
const wchar_t *input_get_bind_mode()
|
||||
wcstring input_get_bind_mode()
|
||||
{
|
||||
const wchar_t *bind_mode = DEFAULT_BIND_MODE;
|
||||
const env_var_t bind_mode_var = env_get_string(FISH_BIND_MODE_VAR);
|
||||
if(!bind_mode_var.missing())
|
||||
{
|
||||
bind_mode = bind_mode_var.c_str();
|
||||
}
|
||||
return bind_mode;
|
||||
env_var_t mode = env_get_string(FISH_BIND_MODE_VAR);
|
||||
return mode.missing() ? DEFAULT_BIND_MODE : mode;
|
||||
}
|
||||
|
||||
/**
|
||||
Set the current bind mode
|
||||
*/
|
||||
bool input_set_bind_mode(const wchar_t *bm)
|
||||
void input_set_bind_mode(const wcstring &bm)
|
||||
{
|
||||
if(wcscmp(bm, input_get_bind_mode()))
|
||||
env_set(FISH_BIND_MODE_VAR, bm, ENV_GLOBAL);
|
||||
return true;
|
||||
env_set(FISH_BIND_MODE_VAR, bm.c_str(), ENV_GLOBAL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -375,7 +368,7 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t
|
|||
// debug( 0, L"Add mapping from %ls to %ls in mode %ls", escape(sequence, 1), escape(command, 1 ), mode);
|
||||
|
||||
// remove existing mappings with this sequence
|
||||
std::vector<wcstring> commands_vector(commands, commands + commands_len);
|
||||
const wcstring_list_t commands_vector(commands, commands + commands_len);
|
||||
|
||||
for (size_t i=0; i<mapping_list.size(); i++)
|
||||
{
|
||||
|
@ -387,7 +380,10 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t
|
|||
return;
|
||||
}
|
||||
}
|
||||
mapping_list.push_back(input_mapping_t(sequence, commands_vector, mode, sets_mode));
|
||||
|
||||
// add a new mapping, using the next order
|
||||
const input_mapping_t new_mapping = input_mapping_t(sequence, commands_vector, mode, sets_mode);
|
||||
input_mapping_insert_sorted(new_mapping);
|
||||
}
|
||||
|
||||
void input_mapping_add(const wchar_t *sequence, const wchar_t *command,
|
||||
|
@ -559,9 +555,10 @@ static void input_mapping_execute(const input_mapping_t &m)
|
|||
/* By default input functions always succeed */
|
||||
input_function_status = true;
|
||||
|
||||
for(int i = m.commands.size() - 1; i >= 0; i--)
|
||||
size_t idx = m.commands.size();
|
||||
while (idx--)
|
||||
{
|
||||
wcstring command = m.commands.at(i);
|
||||
wcstring command = m.commands.at(idx);
|
||||
wchar_t code = input_function_get_code(command);
|
||||
if (code != (wchar_t)-1)
|
||||
{
|
||||
|
@ -569,9 +566,10 @@ static void input_mapping_execute(const input_mapping_t &m)
|
|||
}
|
||||
}
|
||||
|
||||
for(int i = m.commands.size() - 1; i >= 0; i--)
|
||||
idx = m.commands.size();
|
||||
while (idx--)
|
||||
{
|
||||
wcstring command = m.commands.at(i);
|
||||
wcstring command = m.commands.at(idx);
|
||||
wchar_t code = input_function_get_code(command);
|
||||
if (code != (wchar_t)-1)
|
||||
{
|
||||
|
@ -650,7 +648,7 @@ static void input_mapping_execute_matching_or_generic()
|
|||
{
|
||||
const input_mapping_t *generic = NULL;
|
||||
|
||||
const wchar_t *bind_mode = input_get_bind_mode();
|
||||
const wcstring bind_mode = input_get_bind_mode();
|
||||
|
||||
for (int i = 0; i < mapping_list.size(); i++)
|
||||
{
|
||||
|
@ -659,7 +657,7 @@ static void input_mapping_execute_matching_or_generic()
|
|||
//debug(0, L"trying mapping (%ls,%ls,%ls)\n", escape(m.seq.c_str(), 1),
|
||||
// m.mode.c_str(), m.sets_mode.c_str());
|
||||
|
||||
if(wcscmp(m.mode.c_str(), bind_mode))
|
||||
if (m.mode != bind_mode)
|
||||
{
|
||||
//debug(0, L"skipping mapping because mode %ls != %ls\n", m.mode.c_str(), input_get_bind_mode());
|
||||
continue;
|
||||
|
@ -745,18 +743,20 @@ wint_t input_readch()
|
|||
}
|
||||
}
|
||||
|
||||
void input_mapping_get_names(wcstring_list_t &lst)
|
||||
wcstring_list_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;
|
||||
result.reserve(local_list.size());
|
||||
|
||||
for (size_t i=0; i<local_list.size(); i++)
|
||||
{
|
||||
const input_mapping_t &m = local_list.at(i);
|
||||
lst.push_back(wcstring(m.seq));
|
||||
result.push_back(m.seq);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -784,22 +784,23 @@ bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool input_mapping_get(const wcstring &sequence, std::vector<wcstring> &cmds, wcstring &mode, wcstring &sets_mode)
|
||||
bool input_mapping_get(const wcstring &sequence, wcstring_list_t *out_cmds, wcstring *out_mode, wcstring *out_sets_mode)
|
||||
{
|
||||
size_t i, sz = mapping_list.size();
|
||||
|
||||
for (i=0; i<sz; i++)
|
||||
bool result = false;
|
||||
size_t sz = mapping_list.size();
|
||||
for (size_t i=0; i<sz; i++)
|
||||
{
|
||||
const input_mapping_t &m = mapping_list.at(i);
|
||||
if (sequence == m.seq)
|
||||
{
|
||||
cmds = m.commands;
|
||||
mode = m.mode;
|
||||
sets_mode = m.sets_mode;
|
||||
return true;
|
||||
*out_cmds = m.commands;
|
||||
*out_mode = m.mode;
|
||||
*out_sets_mode = m.sets_mode;
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
10
input.h
10
input.h
|
@ -128,9 +128,9 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t
|
|||
const wchar_t *mode = DEFAULT_BIND_MODE, const wchar_t *new_mode = DEFAULT_BIND_MODE);
|
||||
|
||||
/**
|
||||
Insert all mapping names into the specified wcstring_list_t
|
||||
Returns all mapping names
|
||||
*/
|
||||
void input_mapping_get_names(wcstring_list_t &lst);
|
||||
wcstring_list_t input_mapping_get_names();
|
||||
|
||||
/**
|
||||
Erase binding for specified key sequence
|
||||
|
@ -140,17 +140,17 @@ bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode = DEFAULT_
|
|||
/**
|
||||
Gets the command bound to the specified key sequence. Returns true if it exists, false if not.
|
||||
*/
|
||||
bool input_mapping_get(const wcstring &sequence, std::vector<wcstring> &cmds, wcstring &mode, wcstring &new_mode);
|
||||
bool input_mapping_get(const wcstring &sequence, wcstring_list_t *out_cmds, wcstring *out_mode, wcstring *out_new_mode);
|
||||
|
||||
/**
|
||||
Return the current bind mode
|
||||
*/
|
||||
const wchar_t *input_get_bind_mode();
|
||||
wcstring input_get_bind_mode();
|
||||
|
||||
/**
|
||||
Set the current bind mode
|
||||
*/
|
||||
bool input_set_bind_mode(const wchar_t *bind_mode);
|
||||
void input_set_bind_mode(const wcstring &bind_mode);
|
||||
|
||||
|
||||
wchar_t input_function_pop_arg();
|
||||
|
|
20
reader.cpp
20
reader.cpp
|
@ -626,9 +626,9 @@ static void reader_repaint()
|
|||
cmd_line->size(),
|
||||
&colors[0],
|
||||
&indents[0],
|
||||
cursor_position,
|
||||
data->sel_start_pos,
|
||||
data->sel_stop_pos,
|
||||
cursor_position,
|
||||
data->current_page_rendering,
|
||||
focused_on_pager);
|
||||
|
||||
|
@ -2446,23 +2446,14 @@ size_t reader_get_cursor_pos()
|
|||
|
||||
bool reader_get_selection(size_t *start, size_t *len)
|
||||
{
|
||||
if (!data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! data->sel_active)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
bool result = false;
|
||||
if (data != NULL && data->sel_active)
|
||||
{
|
||||
*start = data->sel_start_pos;
|
||||
*len = std::min(data->sel_stop_pos - data->sel_start_pos + 1, data->command_line.size());
|
||||
return true;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3833,7 +3824,6 @@ const wchar_t *reader_readline(void)
|
|||
line_offset_old = el->position - parse_util_get_offset_from_line(el->text, line_old);
|
||||
total_offset_new = parse_util_get_offset(el->text, line_new, line_offset_old - 4*(indent_new-indent_old));
|
||||
update_buff_pos(el, total_offset_new);
|
||||
el->position = total_offset_new;
|
||||
reader_repaint_needed();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue