mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
Add experimental support for selection and visual mode
This commit is contained in:
@@ -211,6 +211,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
||||
int append_mode=0;
|
||||
|
||||
int function_mode = 0;
|
||||
int selection_mode = 0;
|
||||
|
||||
int tokenize = 0;
|
||||
|
||||
@@ -315,6 +316,10 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
||||
L"search-mode", no_argument, 0, 'S'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"selection", no_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
@@ -402,6 +407,10 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
||||
search_mode = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
selection_mode = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return 0;
|
||||
@@ -465,6 +474,26 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (selection_mode)
|
||||
{
|
||||
size_t sel_start, sel_stop;
|
||||
const wchar_t *buffer = reader_get_buffer();
|
||||
if(reader_get_selection_pos(sel_start, sel_stop))
|
||||
{
|
||||
size_t len = std::min(sel_stop - sel_start + 1, wcslen(buffer));
|
||||
wchar_t *selection = new wchar_t[len];
|
||||
selection = wcsncpy(selection, current_buffer + sel_start, len);
|
||||
|
||||
append_format(stdout_buffer, selection);
|
||||
delete selection;
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stdout_buffer, L"");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user