Skip to content

Commit

Permalink
Add vimscript that could select-and-insert a candidate with a single …
Browse files Browse the repository at this point in the history
…keypress (#191)
  • Loading branch information
akiyosi committed Jan 30, 2021
1 parent 194cbb8 commit 666bfe7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/go.yml
Expand Up @@ -69,6 +69,7 @@ jobs:
run: |
cd ${{ github.workspace }}/src/github.com/${{ github.repository }}/cmd/goneovim
$(go env GOPATH)/bin/qtdeploy build desktop
cp -pR ../../runtime ./deploy/linux/
- name: Add executable
run: |
Expand Down Expand Up @@ -141,6 +142,7 @@ jobs:
run: |
cd ${{ github.workspace }}/src/github.com/${{ github.repository }}/cmd/goneovim
$(go env GOPATH)/bin/qtdeploy build desktop
cp -pR ../../runtime ./deploy/darwin/goneovim.app/Contents/Resources/
- name: Upload for macos
uses: actions/upload-artifact@v1
Expand Down Expand Up @@ -175,7 +177,7 @@ jobs:
curl -sL --retry 10 --retry-delay 60 -O https://aka.ms/vs/15/release/vs_buildtools.exe
New-Item -Path BuildTools -ItemType Directory
.\vs_BuildTools.exe --quiet --wait --norestart --nocache --installPath ${{ github.workspace }}\BuildTools --add Microsoft.VisualStudio.Workload.VCTools --includeOptional
Start-Sleep -s 720
Start-Sleep -s 650
- name: Check MSVC 2017 Visual C++ Buildtools installation
run : |
Expand Down Expand Up @@ -314,6 +316,7 @@ jobs:
run: |
cd ${{ github.workspace }}\src\github.com\${{ github.repository }}\cmd\goneovim
${{ github.workspace }}\bin\qtdeploy build desktop
cp -pR ../../runtime ./deploy/windows
- name: Upload for windows
uses: actions/upload-artifact@v1
Expand Down
Empty file added Makefile
Empty file.
10 changes: 8 additions & 2 deletions editor/popupmenu.go
Expand Up @@ -286,7 +286,7 @@ func (p *PopupMenu) showItems(args []interface{}) {

popupItem.setItem(item, selected == i)

popupItem.setDigit(i + 1)
popupItem.setDigit(i+1, gridid)
popupItem.hide()
popupItem.show()

Expand Down Expand Up @@ -481,10 +481,16 @@ func (p *PopupMenu) scroll(n int) {
p.setWidgetWidth()
}

func (p *PopupItem) setDigit(num int) {
func (p *PopupItem) setDigit(num int, gridid int) {
if !editor.config.Popupmenu.ShowDigit {
return
}
if gridid == 1 {
p.digitLabel.Hide()
return
} else {
p.digitLabel.Show()
}
if num == 10 {
num = 0
}
Expand Down
29 changes: 20 additions & 9 deletions editor/workspace.go
Expand Up @@ -426,16 +426,24 @@ func (w *Workspace) startNvim(path string) error {
var neovim *nvim.Nvim
var err error

option := []string{
"--cmd",
"let g:gonvim_running=1",
"--cmd",
"let g:goneovim=1",
"--cmd",
"set termguicolors",
}
appdirpath := core.QCoreApplication_ApplicationDirPath()

s := fmt.Sprintf("let &rtp.=',%s'", appdirpath)
if editor.config.Popupmenu.ShowDigit {
option = append(option, "--cmd")
option = append(option, s)
}
option = append(option, "--embed")
childProcessArgs := nvim.ChildProcessArgs(
append([]string{
"--cmd",
"let g:gonvim_running=1",
"--cmd",
"let g:goneovim=1",
"--cmd",
"set termguicolors",
"--embed",
}, editor.args...)...,
append(option, editor.args...)...,
)
if editor.opts.Server != "" {
// Attaching to remote nvim session
Expand Down Expand Up @@ -702,6 +710,9 @@ func (w *Workspace) loadGinitVim() {
execGinitVim := fmt.Sprintf(`call execute(split('%s', '\n'))`, scripts)
w.nvim.Command(execGinitVim)
}
if editor.config.Popupmenu.ShowDigit {
w.nvim.Command("runtime! runtime/plugin/showdigit.vim")
}
}

func (w *Workspace) getNvimOptions() {
Expand Down
12 changes: 12 additions & 0 deletions runtime/plugin/showdigit.vim
@@ -0,0 +1,12 @@
" map 0-9 to nth item
let s:shiftKeys = '!@#$%^&*('
for s:i in range(0, 9)
exe printf('inoremap <expr> %d pumvisible() ? <sid>select_pum(%d) : %d ', s:i, s:i, s:i)
endfor

function! s:select_pum(index)
let compInfo = complete_info()
let idx = a:index == 0 ? 10 : a:index - 1
let d = idx - compInfo.selected
return repeat( d > 0 ? "\<c-n>" : "\<c-p>", abs(d)) . "\<C-y>"
endfunction

0 comments on commit 666bfe7

Please sign in to comment.