mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-01 03:54:58 +08:00
Minor cleanup of kill ring
This commit is contained in:
parent
b68d3b84de
commit
0841072462
19
src/kill.cpp
19
src/kill.cpp
|
@ -17,10 +17,11 @@
|
|||
typedef std::list<wcstring> kill_list_t;
|
||||
static kill_list_t kill_list;
|
||||
|
||||
void kill_add(const wcstring &str) {
|
||||
void kill_add(wcstring str) {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
if (str.empty()) return;
|
||||
kill_list.push_front(str);
|
||||
if (!str.empty()) {
|
||||
kill_list.push_front(std::move(str));
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove first match for specified string from circular list.
|
||||
|
@ -35,19 +36,19 @@ void kill_replace(const wcstring &old, const wcstring &newv) {
|
|||
kill_add(newv);
|
||||
}
|
||||
|
||||
const wchar_t *kill_yank_rotate() {
|
||||
wcstring kill_yank_rotate() {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
// Move the first element to the end.
|
||||
if (kill_list.empty()) {
|
||||
return NULL;
|
||||
return {};
|
||||
}
|
||||
kill_list.splice(kill_list.end(), kill_list, kill_list.begin());
|
||||
return kill_list.front().c_str();
|
||||
return kill_list.front();
|
||||
}
|
||||
|
||||
const wchar_t *kill_yank() {
|
||||
wcstring kill_yank() {
|
||||
if (kill_list.empty()) {
|
||||
return L"";
|
||||
return {};
|
||||
}
|
||||
return kill_list.front().c_str();
|
||||
return kill_list.front();
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
void kill_replace(const wcstring &old, const wcstring &newv);
|
||||
|
||||
/// Add a string to the top of the killring.
|
||||
void kill_add(const wcstring &str);
|
||||
void kill_add(wcstring str);
|
||||
|
||||
/// Rotate the killring.
|
||||
const wchar_t *kill_yank_rotate();
|
||||
wcstring kill_yank_rotate();
|
||||
|
||||
/// Paste from the killring.
|
||||
const wchar_t *kill_yank();
|
||||
wcstring kill_yank();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2391,7 +2391,6 @@ static bool event_is_normal_char(const char_event_t &evt) {
|
|||
maybe_t<wcstring> reader_data_t::readline(int nchars) {
|
||||
int last_char = 0;
|
||||
size_t yank_len = 0;
|
||||
const wchar_t *yank_str;
|
||||
bool comp_empty = true;
|
||||
std::vector<completion_t> comp;
|
||||
int finished = 0;
|
||||
|
@ -2746,18 +2745,18 @@ maybe_t<wcstring> reader_data_t::readline(int nchars) {
|
|||
break;
|
||||
}
|
||||
case R_YANK: {
|
||||
yank_str = kill_yank();
|
||||
wcstring yank_str = kill_yank();
|
||||
insert_string(active_edit_line(), yank_str);
|
||||
yank_len = std::wcslen(yank_str);
|
||||
yank_len = yank_str.size();
|
||||
break;
|
||||
}
|
||||
case R_YANK_POP: {
|
||||
if (yank_len) {
|
||||
for (size_t i = 0; i < yank_len; i++) remove_backward();
|
||||
|
||||
yank_str = kill_yank_rotate();
|
||||
wcstring yank_str = kill_yank_rotate();
|
||||
insert_string(active_edit_line(), yank_str);
|
||||
yank_len = std::wcslen(yank_str);
|
||||
yank_len = yank_str.size();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user