mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.0.1112: can't get size or current index from quickfix list
Problem: Can't get size or current index from quickfix list.
Solution: Add "idx" and "size" options. (Yegappan Lakshmanan)
fc2b270cfd
This commit is contained in:
parent
e52f6f21a1
commit
7b219c638d
@ -2196,8 +2196,7 @@ void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit)
|
||||
old_qf_ptr = qf_ptr;
|
||||
qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
|
||||
old_qf_index = qf_index;
|
||||
if (dir == FORWARD || dir == FORWARD_FILE || dir == BACKWARD
|
||||
|| dir == BACKWARD_FILE) { // next/prev valid entry
|
||||
if (dir != 0) { // next/prev valid entry
|
||||
qf_ptr = get_nth_valid_entry(qi, errornr, qf_ptr, &qf_index, dir);
|
||||
if (qf_ptr == NULL) {
|
||||
qf_ptr = old_qf_ptr;
|
||||
@ -4202,6 +4201,8 @@ enum {
|
||||
QF_GETLIST_WINID = 0x8,
|
||||
QF_GETLIST_CONTEXT = 0x10,
|
||||
QF_GETLIST_ID = 0x20,
|
||||
QF_GETLIST_IDX = 0x40,
|
||||
QF_GETLIST_SIZE = 0x80,
|
||||
QF_GETLIST_ALL = 0xFF
|
||||
};
|
||||
|
||||
@ -4336,6 +4337,13 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
|
||||
if (tv_dict_find(what, S_LEN("items")) != NULL) {
|
||||
flags |= QF_GETLIST_ITEMS;
|
||||
}
|
||||
if (tv_dict_find(what, S_LEN("idx")) != NULL) {
|
||||
flags |= QF_GETLIST_IDX;
|
||||
}
|
||||
if (tv_dict_find(what, S_LEN("size")) != NULL) {
|
||||
flags |= QF_GETLIST_SIZE;
|
||||
}
|
||||
|
||||
|
||||
if (flags & QF_GETLIST_TITLE) {
|
||||
char_u *t = qi->qf_lists[qf_idx].qf_title;
|
||||
@ -4376,6 +4384,20 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
|
||||
status = tv_dict_add_nr(retdict, S_LEN("id"), qi->qf_lists[qf_idx].qf_id);
|
||||
}
|
||||
|
||||
if ((status == OK) && (flags & QF_GETLIST_IDX)) {
|
||||
int idx = qi->qf_lists[qf_idx].qf_index;
|
||||
if (qi->qf_lists[qf_idx].qf_count == 0) {
|
||||
// For empty lists, qf_index is set to 1
|
||||
idx = 0;
|
||||
}
|
||||
status = tv_dict_add_nr(retdict, S_LEN("idx"), idx);
|
||||
}
|
||||
|
||||
if ((status == OK) && (flags & QF_GETLIST_SIZE)) {
|
||||
status = tv_dict_add_nr(retdict, S_LEN("size"),
|
||||
qi->qf_lists[qf_idx].qf_count);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -430,6 +430,19 @@ func Xtest_browse(cchar)
|
||||
|
||||
call delete('Xqftestfile1')
|
||||
call delete('Xqftestfile2')
|
||||
|
||||
" Should be able to use next/prev with invalid entries
|
||||
Xexpr ""
|
||||
call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
|
||||
call assert_equal(0, g:Xgetlist({'size' : 0}).size)
|
||||
Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
|
||||
call assert_equal(5, g:Xgetlist({'size' : 0}).size)
|
||||
Xlast
|
||||
call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
|
||||
Xfirst
|
||||
call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
|
||||
2Xnext
|
||||
call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
|
||||
endfunc
|
||||
|
||||
func Test_browse()
|
||||
|
Loading…
Reference in New Issue
Block a user