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

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.