Skip to content

Commit

Permalink
feat(list): improve list options
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Aug 18, 2019
1 parent b850902 commit 762172a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
12 changes: 9 additions & 3 deletions autoload/coc/list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,20 @@ function! coc#list#status(name)
return get(b:list_status, a:name, '')
endfunction

function! coc#list#create(position, height, name)
function! coc#list#create(position, height, name, numberSelect)
nohlsearch
if a:position ==# 'tab'
execute 'silent tabe list:///'.a:name
else
execute 'silent keepalt '.(a:position ==# 'top' ? '' : 'botright').a:height.'sp list:///'.a:name
execute 'resize '.a:height
endif
if a:numberSelect
setl number
else
setl nonumber
setl foldcolumn=2
endif
return [bufnr('%'), win_getid()]
endfunction

Expand All @@ -212,9 +218,9 @@ function! coc#list#setup(source)
\ ]
call setwinvar(winnr(), '&statusline', join(statusParts, ' '))
setl buftype=nofile nobuflisted nofen nowrap
setl number norelativenumber bufhidden=wipe cursorline winfixheight
setl norelativenumber bufhidden=wipe cursorline winfixheight
setl tabstop=1 nolist nocursorcolumn
setl signcolumn=yes
setl signcolumn=auto
setl filetype=list
syntax case ignore
let source = a:source[8:]
Expand Down
25 changes: 15 additions & 10 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45355,7 +45355,12 @@ augroup end`;
try {
let filepath = path_1.default.join(os_1.default.tmpdir(), `coc-${process.pid}.vim`);
await fs_2.writeFile(filepath, content);
await this.nvim.command(`source ${filepath}`);
let cmd = `source ${filepath}`;
const isCygwin = await this.nvim.eval('has("win32unix")');
if (isCygwin && index_1.platform.isWindows) {
cmd = `execute "source" . substitute(system('cygpath ${filepath.replace(/\\/g, '/')}'), '\\n', '', 'g')`;
}
await this.nvim.command(cmd);
}
catch (e) {
this.showMessage(`Can't create tmp file: ${e.message}`, 'error');
Expand Down Expand Up @@ -50783,12 +50788,12 @@ function getChange(oldStr, newStr, cursorEnd) {
newText = newStr.slice(start, nl - endOffset);
if (ol == nl && start == end)
return null;
// optimize for add new line(s)
if (start == end) {
let pre = start == 0 ? '' : newStr[start - 1];
if (pre && pre != '\n'
&& oldStr[start] == '\n'
&& newText.startsWith('\n')) {
// optimize for add new line(s)
return { start: start + 1, end: end + 1, newText: newText.slice(1) + '\n' };
}
}
Expand Down Expand Up @@ -54670,7 +54675,7 @@ class Plugin extends events_1.EventEmitter {
return false;
}
get version() {
return workspace_1.default.version + ( true ? '-' + "6dd955143d" : undefined);
return workspace_1.default.version + ( true ? '-' + "5b5377732d" : undefined);
}
async showInfo() {
if (!this.infoChannel) {
Expand Down Expand Up @@ -79900,7 +79905,7 @@ class ListManager {
}
else {
this.ui.addHighlights(highlights);
await this.ui.drawItems(items, this.name, this.listOptions.position, reload);
await this.ui.drawItems(items, this.name, this.listOptions, reload);
}
}, null, this.disposables);
this.registerList(new links_1.default(nvim));
Expand Down Expand Up @@ -79953,7 +79958,7 @@ class ListManager {
this.activated = true;
this.window = await nvim.window;
this.prompt.start();
await ui.resume(name, this.listOptions.position);
await ui.resume(name, this.listOptions);
}
async doAction(name) {
let { currList } = this;
Expand Down Expand Up @@ -83232,9 +83237,9 @@ class ListUI {
nvim.command(`silent! bd! ${bufnr}`, true);
}
}
async resume(name, position) {
async resume(name, listOptions) {
let { items, selected, nvim, signOffset } = this;
await this.drawItems(items, name, position, true);
await this.drawItems(items, name, listOptions, true);
if (selected.size > 0 && this.bufnr) {
nvim.pauseNotification();
for (let lnum of selected) {
Expand Down Expand Up @@ -83339,17 +83344,17 @@ class ListUI {
});
}
}
async drawItems(items, name, position = 'bottom', reload = false) {
async drawItems(items, name, listOptions, reload = false) {
let { bufnr, config, nvim } = this;
this.newTab = position == 'tab';
this.newTab = listOptions.position == 'tab';
let maxHeight = config.get('maxHeight', 12);
let height = Math.max(1, Math.min(items.length, maxHeight));
let limitLines = config.get('limitLines', 30000);
let curr = this.items[this.index];
this.items = items.slice(0, limitLines);
if (bufnr == 0 && !this.creating) {
this.creating = true;
let [bufnr, winid] = await nvim.call('coc#list#create', [position, height, name]);
let [bufnr, winid] = await nvim.call('coc#list#create', [listOptions.position, height, name, listOptions.numberSelect]);
this._bufnr = bufnr;
this.window = nvim.createWindow(winid);
this.height = height;
Expand Down

0 comments on commit 762172a

Please sign in to comment.