Skip to content

Commit 762172a

Browse files
committed
feat(list): improve list options
1 parent b850902 commit 762172a

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

autoload/coc/list.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,20 @@ function! coc#list#status(name)
189189
return get(b:list_status, a:name, '')
190190
endfunction
191191

192-
function! coc#list#create(position, height, name)
192+
function! coc#list#create(position, height, name, numberSelect)
193193
nohlsearch
194194
if a:position ==# 'tab'
195195
execute 'silent tabe list:///'.a:name
196196
else
197197
execute 'silent keepalt '.(a:position ==# 'top' ? '' : 'botright').a:height.'sp list:///'.a:name
198198
execute 'resize '.a:height
199199
endif
200+
if a:numberSelect
201+
setl number
202+
else
203+
setl nonumber
204+
setl foldcolumn=2
205+
endif
200206
return [bufnr('%'), win_getid()]
201207
endfunction
202208

@@ -212,9 +218,9 @@ function! coc#list#setup(source)
212218
\ ]
213219
call setwinvar(winnr(), '&statusline', join(statusParts, ' '))
214220
setl buftype=nofile nobuflisted nofen nowrap
215-
setl number norelativenumber bufhidden=wipe cursorline winfixheight
221+
setl norelativenumber bufhidden=wipe cursorline winfixheight
216222
setl tabstop=1 nolist nocursorcolumn
217-
setl signcolumn=yes
223+
setl signcolumn=auto
218224
setl filetype=list
219225
syntax case ignore
220226
let source = a:source[8:]

build/index.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45355,7 +45355,12 @@ augroup end`;
4535545355
try {
4535645356
let filepath = path_1.default.join(os_1.default.tmpdir(), `coc-${process.pid}.vim`);
4535745357
await fs_2.writeFile(filepath, content);
45358-
await this.nvim.command(`source ${filepath}`);
45358+
let cmd = `source ${filepath}`;
45359+
const isCygwin = await this.nvim.eval('has("win32unix")');
45360+
if (isCygwin && index_1.platform.isWindows) {
45361+
cmd = `execute "source" . substitute(system('cygpath ${filepath.replace(/\\/g, '/')}'), '\\n', '', 'g')`;
45362+
}
45363+
await this.nvim.command(cmd);
4535945364
}
4536045365
catch (e) {
4536145366
this.showMessage(`Can't create tmp file: ${e.message}`, 'error');
@@ -50783,12 +50788,12 @@ function getChange(oldStr, newStr, cursorEnd) {
5078350788
newText = newStr.slice(start, nl - endOffset);
5078450789
if (ol == nl && start == end)
5078550790
return null;
50791+
// optimize for add new line(s)
5078650792
if (start == end) {
5078750793
let pre = start == 0 ? '' : newStr[start - 1];
5078850794
if (pre && pre != '\n'
5078950795
&& oldStr[start] == '\n'
5079050796
&& newText.startsWith('\n')) {
50791-
// optimize for add new line(s)
5079250797
return { start: start + 1, end: end + 1, newText: newText.slice(1) + '\n' };
5079350798
}
5079450799
}
@@ -54670,7 +54675,7 @@ class Plugin extends events_1.EventEmitter {
5467054675
return false;
5467154676
}
5467254677
get version() {
54673-
return workspace_1.default.version + ( true ? '-' + "6dd955143d" : undefined);
54678+
return workspace_1.default.version + ( true ? '-' + "5b5377732d" : undefined);
5467454679
}
5467554680
async showInfo() {
5467654681
if (!this.infoChannel) {
@@ -79900,7 +79905,7 @@ class ListManager {
7990079905
}
7990179906
else {
7990279907
this.ui.addHighlights(highlights);
79903-
await this.ui.drawItems(items, this.name, this.listOptions.position, reload);
79908+
await this.ui.drawItems(items, this.name, this.listOptions, reload);
7990479909
}
7990579910
}, null, this.disposables);
7990679911
this.registerList(new links_1.default(nvim));
@@ -79953,7 +79958,7 @@ class ListManager {
7995379958
this.activated = true;
7995479959
this.window = await nvim.window;
7995579960
this.prompt.start();
79956-
await ui.resume(name, this.listOptions.position);
79961+
await ui.resume(name, this.listOptions);
7995779962
}
7995879963
async doAction(name) {
7995979964
let { currList } = this;
@@ -83232,9 +83237,9 @@ class ListUI {
8323283237
nvim.command(`silent! bd! ${bufnr}`, true);
8323383238
}
8323483239
}
83235-
async resume(name, position) {
83240+
async resume(name, listOptions) {
8323683241
let { items, selected, nvim, signOffset } = this;
83237-
await this.drawItems(items, name, position, true);
83242+
await this.drawItems(items, name, listOptions, true);
8323883243
if (selected.size > 0 && this.bufnr) {
8323983244
nvim.pauseNotification();
8324083245
for (let lnum of selected) {
@@ -83339,17 +83344,17 @@ class ListUI {
8333983344
});
8334083345
}
8334183346
}
83342-
async drawItems(items, name, position = 'bottom', reload = false) {
83347+
async drawItems(items, name, listOptions, reload = false) {
8334383348
let { bufnr, config, nvim } = this;
83344-
this.newTab = position == 'tab';
83349+
this.newTab = listOptions.position == 'tab';
8334583350
let maxHeight = config.get('maxHeight', 12);
8334683351
let height = Math.max(1, Math.min(items.length, maxHeight));
8334783352
let limitLines = config.get('limitLines', 30000);
8334883353
let curr = this.items[this.index];
8334983354
this.items = items.slice(0, limitLines);
8335083355
if (bufnr == 0 && !this.creating) {
8335183356
this.creating = true;
83352-
let [bufnr, winid] = await nvim.call('coc#list#create', [position, height, name]);
83357+
let [bufnr, winid] = await nvim.call('coc#list#create', [listOptions.position, height, name, listOptions.numberSelect]);
8335383358
this._bufnr = bufnr;
8335483359
this.window = nvim.createWindow(winid);
8335583360
this.height = height;

0 commit comments

Comments
 (0)