mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Add kill-selection function and visual binds for 'y' and 'd'
This commit is contained in:
parent
88eae68987
commit
3728fc7dba
6 changed files with 27 additions and 11 deletions
|
@ -472,14 +472,13 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
||||||
|
|
||||||
if (selection_mode)
|
if (selection_mode)
|
||||||
{
|
{
|
||||||
size_t sel_start, sel_stop;
|
size_t start, len;
|
||||||
const wchar_t *buffer = reader_get_buffer();
|
const wchar_t *buffer = reader_get_buffer();
|
||||||
if(reader_get_selection_pos(sel_start, sel_stop))
|
if(reader_get_selection(start, len))
|
||||||
{
|
{
|
||||||
size_t len = std::min(sel_stop - sel_start + 1, wcslen(buffer));
|
|
||||||
wchar_t *selection = new wchar_t[len + 1];
|
wchar_t *selection = new wchar_t[len + 1];
|
||||||
selection[len] = L'\0';
|
selection[len] = L'\0';
|
||||||
selection = wcsncpy(selection, buffer + sel_start, len);
|
selection = wcsncpy(selection, buffer + start, len);
|
||||||
|
|
||||||
append_format(stdout_buffer, selection);
|
append_format(stdout_buffer, selection);
|
||||||
delete selection;
|
delete selection;
|
||||||
|
|
|
@ -140,6 +140,7 @@ static const wchar_t * const name_arr[] =
|
||||||
L"accept-autosuggestion",
|
L"accept-autosuggestion",
|
||||||
L"begin-selection",
|
L"begin-selection",
|
||||||
L"end-selection",
|
L"end-selection",
|
||||||
|
L"kill-selection"
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -231,7 +232,8 @@ static const wchar_t code_arr[] =
|
||||||
R_SUPPRESS_AUTOSUGGESTION,
|
R_SUPPRESS_AUTOSUGGESTION,
|
||||||
R_ACCEPT_AUTOSUGGESTION,
|
R_ACCEPT_AUTOSUGGESTION,
|
||||||
R_BEGIN_SELECTION,
|
R_BEGIN_SELECTION,
|
||||||
R_END_SELECTION
|
R_END_SELECTION,
|
||||||
|
R_KILL_SELECTION
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
5
input.h
5
input.h
|
@ -62,12 +62,13 @@ enum
|
||||||
R_SUPPRESS_AUTOSUGGESTION,
|
R_SUPPRESS_AUTOSUGGESTION,
|
||||||
R_ACCEPT_AUTOSUGGESTION,
|
R_ACCEPT_AUTOSUGGESTION,
|
||||||
R_BEGIN_SELECTION,
|
R_BEGIN_SELECTION,
|
||||||
R_END_SELECTION
|
R_END_SELECTION,
|
||||||
|
R_KILL_SELECTION
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
#define R_MIN R_NULL
|
#define R_MIN R_NULL
|
||||||
#define R_MAX R_END_SELECTION
|
#define R_MAX R_KILL_SELECTION
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize the terminal by calling setupterm, and set up arrays
|
Initialize the terminal by calling setupterm, and set up arrays
|
||||||
|
|
15
reader.cpp
15
reader.cpp
|
@ -2436,7 +2436,7 @@ size_t reader_get_cursor_pos()
|
||||||
return data->buff_pos;
|
return data->buff_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reader_get_selection_pos(size_t &start, size_t &stop)
|
bool reader_get_selection(size_t &start, size_t &len)
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
|
@ -2449,7 +2449,7 @@ bool reader_get_selection_pos(size_t &start, size_t &stop)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
start = data->sel_start_pos;
|
start = data->sel_start_pos;
|
||||||
stop = data->sel_stop_pos;
|
len = std::min(data->sel_stop_pos - data->sel_start_pos + 1, data->command_length());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3850,6 +3850,17 @@ const wchar_t *reader_readline(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case R_KILL_SELECTION:
|
||||||
|
{
|
||||||
|
bool newv = (last_char != R_KILL_SELECTION);
|
||||||
|
size_t start, len;
|
||||||
|
if(reader_get_selection(start, len))
|
||||||
|
{
|
||||||
|
reader_kill(start, len, KILL_APPEND, newv);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Other, if a normal character, we add it to the command */
|
/* Other, if a normal character, we add it to the command */
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
|
2
reader.h
2
reader.h
|
@ -120,7 +120,7 @@ size_t reader_get_cursor_pos();
|
||||||
Get the current selection range in the command line.
|
Get the current selection range in the command line.
|
||||||
Returns false if there is no active selection, true otherwise.
|
Returns false if there is no active selection, true otherwise.
|
||||||
*/
|
*/
|
||||||
bool reader_get_selection_pos(size_t &start, size_t &stop);
|
bool reader_get_selection(size_t &start, size_t &len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the value of the interrupted flag, which is set by the sigint
|
Return the value of the interrupted flag, which is set by the sigint
|
||||||
|
|
|
@ -192,7 +192,10 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish"
|
||||||
bind -M visual -k left backward-char
|
bind -M visual -k left backward-char
|
||||||
bind -M visual h backward-char
|
bind -M visual h backward-char
|
||||||
bind -M visual l forward-char
|
bind -M visual l forward-char
|
||||||
bind -M visual '"*y' "commandline -s | xsel -p"
|
|
||||||
|
bind -M visual -m default d kill-selection end-selection force-repaint
|
||||||
|
bind -M visual -m default y kill-selection yank end-selection force-repaint
|
||||||
|
bind -M visual -m default '"*y' "commandline -s | xsel -p" end-selection force-repaint
|
||||||
|
|
||||||
bind -M visual -m default \cc end-selection force-repaint
|
bind -M visual -m default \cc end-selection force-repaint
|
||||||
bind -M visual -m default \e end-selection force-repaint
|
bind -M visual -m default \e end-selection force-repaint
|
||||||
|
|
Loading…
Reference in a new issue