Skip to content

weirongxu/coc-floatinput

Repository files navigation

coc-floatinput

Floating input for coc.nvim

Note: Vim popupwin doesn't support the focus feature, So this extension only works on neovim

Install

:CocInstall coc-floatinput

Keymaps

nmap <silent> <Leader>: <Plug>(coc-floatinput-command)

nmap <silent> <Leader>c: <Plug>(coc-floatinput-coc-command)

nmap <silent> <Leader>rn <Plug>(coc-floatinput-rename) removed, see #21

Screenshots

Highlight

autocmd ColorScheme *
      \ hi CocHelperNormalFloatBorder guifg=#dddddd guibg=#575B54
      \ | hi CocHelperNormalFloat guibg=#575B54

API

Use coc-floatinput API in other extensions

// Get coc-floatinput API

// input FloatInputType only
import type { FloatInputType } from 'coc-floatinput';

import { extensions } from 'coc.nvim';

let floatInputExt: FloatInputType | undefined;

async function getFloatInputApi() {
  if (!floatInputExt) {
    floatInputExt = extensions.all.find((e) => e.id === 'coc-floatinput') as
      | Extension<FloatInputType>
      | undefined;
  }
  return floatInputExt?.exports;
}

FloatingUI

// Get FloatingUI
async function getFloatUI() {
  return (await getFloatInputApi())?.FloatingUI;
}

string input

const FloatUI = await getFloatUI();
await FloatUI?.stringInput({
  prompt: 'Input your string',
  defaultValue: 'default string',
});

number input

const FloatUI = await getFloatUI();
await FloatUI?.numberInput({
  prompt: 'Input your number',
  defaultValue: 1,
});

confirm

const FloatUI = await getFloatUI();
await FloatUI?.confirm({
  prompt: 'Are you sure',
  values: ['yes', 'no', 'skip'],
  defaultValue: 'yes',
});

Status window

Enable floatinput status window.

coc-settings.json

{
  "floatinput.status.enabled": true
}

Avoid only floating window error

if has('nvim')
  function! s:is_float(winnr)
    let winid = win_getid(a:winnr)
    return !empty(nvim_win_get_config(winid)['relative'])
  endfunction

  function! s:quit_pre()
    let cur_nr = winnr()
    if s:is_float(cur_nr)
      return
    endif
    let last_nr = winnr('$')
    for nr in range(last_nr, 1, -1)
      if s:is_float(nr)
        continue
      endif
      if nr == 1
        only
      else
        break
      endif
    endfor
  endfunction

  autocmd QuitPre * call <SID>quit_pre()
endif

License

MIT


This extension is created by create-coc-extension