1
0
mirror of https://github.com/amix/vimrc synced 2025-07-27 23:45:00 +08:00

Update coc.nvim

This commit is contained in:
Kurtis Moxley
2022-05-19 22:14:37 +08:00
parent 8f2091a3e4
commit 6bd73b104c
7 changed files with 444 additions and 248 deletions

View File

@ -5,7 +5,8 @@ const readline = require("readline")
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
escapeCodeTimeout: 0
escapeCodeTimeout: 0,
prompt: ''
})
rl.setPrompt('')
let value = process.argv[2]
@ -13,37 +14,70 @@ if (value) {
rl.write(value)
}
rl.on('line', input => {
let text = input.replace(/"/g, '\\"')
console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['confirm', text]])))
send(['confirm', input])
process.exit()
})
let original_ttyWrite = rl._ttyWrite
rl._ttyWrite = function (code, key) {
if (key.name === 'enter') {
send(['send', '<C-j>'])
return ''
}
original_ttyWrite.apply(rl, arguments)
send(['change', rl.line])
}
function createSequences(str) {
return '\033]51;' + str + '\x07'
}
process.stdin.on('keypress', (_, key) => {
function send(args) {
process.stdout.write(createSequences(JSON.stringify(['call', 'CocPopupCallback', args])))
}
process.stdin.on('keypress', (e, key) => {
if (key) {
let k = getKey(key)
if (k == '<bs>') {
return
}
if (k == '<cr>') {
process.exit()
return
}
if (k == '<esc>') {
console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['exit', '']])))
send(['exit', ''])
process.exit()
return
}
if (k) {
console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['send', k]])))
send(['send', k])
return
}
}
})
function getKey(key) {
if (key.ctrl === true) {
if (key.name == 'n') {
return '<C-n>'
}
if (key.name == 'p') {
return '<C-p>'
}
if (key.name == 'j') {
return '<C-j>'
}
if (key.name == 'k') {
return '<C-k>'
}
if (key.name == 'f') {
return '<C-f>'
}
if (key.name == 'b') {
return '<C-b>'
}
if (key.sequence == '\x00') {
return '<C-@>'
}
}
if (key.sequence == '\u001b') {
return '<esc>'
}
@ -53,16 +87,6 @@ function getKey(key) {
if (key.sequence == '\t') {
return key.shift ? '<s-tab>' : '<tab>'
}
// handle them can cause bug with terminal
// if (key.name == 'backspace') {
// return '<bs>'
// }
// if (key.name == 'left') {
// return '<left>'
// }
// if (key.name == 'right') {
// return '<right>'
// }
if (key.name == 'up') {
return '<up>'
}