diff options
Diffstat (limited to 'src/nvim/quickfix.c')
-rw-r--r-- | src/nvim/quickfix.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 6444661512..bc794addc6 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -4243,10 +4243,22 @@ static int qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict) return status; } +// Return the quickfix/location list number with the given identifier. +// Returns -1 if list is not found. +static int qf_id2nr(const qf_info_T *const qi, const unsigned qfid) +{ + for (int qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) { + if (qi->qf_lists[qf_idx].qf_id == qfid) { + return qf_idx; + } + } + return -1; +} + /// Return quickfix/location list details (title) as a /// dictionary. 'what' contains the details to return. If 'list_idx' is -1, /// then current list is used. Otherwise the specified list is used. -int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) +int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict) { qf_info_T *qi = &ql_info; dictitem_T *di; @@ -4298,12 +4310,8 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) if (di->di_tv.v_type == VAR_NUMBER) { // For zero, use the current list or the list specifed by 'nr' if (di->di_tv.vval.v_number != 0) { - for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) { - if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number) { - break; - } - } - if (qf_idx == qi->qf_listcount) { + qf_idx = qf_id2nr(qi, (unsigned)di->di_tv.vval.v_number); + if (qf_idx == -1) { return FAIL; // List not found } } @@ -4528,12 +4536,8 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action, if (!newlist && (di = tv_dict_find(what, S_LEN("id"))) != NULL) { // Use the quickfix/location list with the specified id if (di->di_tv.v_type == VAR_NUMBER) { - for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) { - if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number) { - break; - } - } - if (qf_idx == qi->qf_listcount) { + qf_idx = qf_id2nr(qi, (unsigned)di->di_tv.vval.v_number); + if (qf_idx == -1) { return FAIL; // List not found } } else { @@ -4565,6 +4569,13 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action, retval = qf_add_entries(qi, qf_idx, di->di_tv.vval.v_list, title_save, action == ' ' ? 'a' : action); + if (action == 'r') { + // When replacing the quickfix list entries using + // qf_add_entries(), the title is set with a ':' prefix. + // Restore the title with the saved title. + xfree(qi->qf_lists[qf_idx].qf_title); + qi->qf_lists[qf_idx].qf_title = vim_strsave(title_save); + } xfree(title_save); } } |