Skip to content

Commit

Permalink
feat(list): c_CTRL-R in coc-list insert mode (#1088)
Browse files Browse the repository at this point in the history
* feat(list): c_CTRL-R in coc-list insert mode

* additional description for insertregister
  • Loading branch information
weirongxu authored and chemzqm committed Aug 17, 2019
1 parent 42c3ae1 commit 5b7749c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/coc.cnx
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,7 @@ LIST MAPPINGS *coc-list-mappings*
<C-n> - 切换到下一个历史匹配输入。
<C-p> - 切换到上一个历史匹配输入。
<C-s> - 切换过滤匹配模式。
<C-r> - 从 vim 寄存器插入内容。
<Tab> - 选择操作项。

正常模式下默认快捷键:
Expand Down Expand Up @@ -1428,6 +1429,7 @@ s - 执行 'split' 操作.
'deletebackward' - 删除后一个字符
'removetail' - 删除后面全部字符
'removeahead' - 删除前面全部字符
'insertregister' - 从 vim 寄存器插入内容
'paste' - 插入系统粘贴板内容到当前位置
'eval' - 执行 viml 表达式并将结果插入到当前位置
'action' - 执行特定操作,使用 <tab> 查看当前列表支持操作
Expand Down
2 changes: 2 additions & 0 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,7 @@ Default mappings in insert mode:
<C-n> - navigate to next input in history.
<C-p> - navigate to previous input in history.
<C-s> - switch matcher for filter items.
<C-r> - insert content from vim register.
<Tab> - select action.

Default mappings in normal mode:
Expand Down Expand Up @@ -2115,6 +2116,7 @@ The mapping expression should be `command:arguments`, available commands:
'deletebackward' - remove next character.
'removetail' - remove characters afterwards.
'removeahead' - remove character ahead.
'insertregister' - insert content from vim register.
'paste' - append text from system clipboard to prompt.
'eval' - append text to prompt from result of viml expression.
'action' - execute action of list, use <tab> to find available actions.
Expand Down
6 changes: 6 additions & 0 deletions src/list/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default class Mappings {
this.add('insert', '<C-u>', () => {
prompt.removeAhead()
})
this.add('insert', '<C-r>', () => {
return prompt.insertRegister()
})
this.add('insert', '<C-d>', () => {
return manager.feedkeys('<C-d>')
})
Expand Down Expand Up @@ -307,6 +310,9 @@ export default class Mappings {
return prompt.removeTail()
case 'removeahead':
return prompt.removeAhead()
case 'insertregister':
await prompt.insertRegister()
return
case 'paste':
await prompt.paste()
return
Expand Down
9 changes: 9 additions & 0 deletions src/list/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ export default class Prompt {
this.addText(ch)
}

public async insertRegister(): Promise<void> {
let ch = await this.nvim.eval('nr2char(getchar())') as string
if (/^[0-9a-z"%#*+/:\-.]$/.test(ch)) {
let text = await this.nvim.call('getreg', ch) as string
text = text.replace(/\n/g, '')
this.addText(text)
}
}

public async paste(): Promise<void> {
await this.eval('@*')
}
Expand Down

0 comments on commit 5b7749c

Please sign in to comment.