Minor cleanup of kill ring

This commit is contained in:
ridiculousfish 2019-03-16 17:26:42 -07:00
parent b68d3b84de
commit 0841072462
3 changed files with 17 additions and 17 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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;
}