Code Monkey home page Code Monkey logo

coc-floatinput's Introduction

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

coc-floatinput's People

Contributors

black-desk avatar dependabot[bot] avatar weirongxu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vim-geek

coc-floatinput's Issues

The path to the extension's directory is wrong

When I install coc-floatinput, I get the following message on startup.

[coc.nvim] Unable to load global extension at /home/xxx/.config/coc/extensions/coc-floatinput: package.json not found

/home/xxx/.config/coc/extensions/node_modules/coc-floatinput is the correct path.

This is the minimal vimrc.

syntax enable
filetype plugin indent on

if has('vim_starting')
	let s:pluin_manager_dir='~/.vim/plugged/vim-plug'
	execute 'set runtimepath+=' . s:pluin_manager_dir
endif

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_global_extensions = [ 'coc-floatinput' ]
call plug#end()

vim: Neovim v0.5.0-695-gf34eeba2d
OS: ArchLinux
coc-floatinput version: 6c2e05e
coc.nvim: https://github.com/neoclide/coc.nvim/tree/825f7f5b89fb1708f18711798ef7a2ba6aa1bde5

Implement the similar function of coc-floatinput-rename directly in coc

augroup CocNvimCustom
  autocmd!

  " float prompt
  function! s:prompt_start()
    iunmap <silent><nowait><buffer> <esc>
    set buftype=
    augroup CocNvimCustomPrompt
      autocmd!
      autocmd WinLeave <buffer> set buftype=nofile
    augroup end
  endfunction

  autocmd User CocOpenFloatPrompt call s:prompt_start()
augroup end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.