16
16
" last position
17
17
let g: quickui #context#cursor = -1
18
18
19
+ " save positions
20
+ let s: previous_cursor = {}
21
+
19
22
20
23
" ----------------------------------------------------------------------
21
24
" compile
@@ -90,7 +93,6 @@ function! quickui#context#compile(items, border)
90
93
endfunc
91
94
92
95
93
-
94
96
" ----------------------------------------------------------------------
95
97
" create menu object
96
98
" ----------------------------------------------------------------------
@@ -103,6 +105,11 @@ function! s:vim_create_context(textlist, opts)
103
105
let hwnd.winid = winid
104
106
let hwnd.index = get (a: opts , ' index' , -1 )
105
107
let hwnd.opts = deepcopy (a: opts )
108
+ if has_key (hwnd.opts, ' savepos' )
109
+ if has_key (s: previous_cursor , hwnd.opts.savepos)
110
+ let hwnd.index = get (s: previous_cursor , hwnd.opts.savepos, 0 )
111
+ endif
112
+ endif
106
113
let opts = {' minwidth' :w , ' maxwidth' :w , ' minheight' :h , ' maxheight' :h }
107
114
if has_key (a: opts , ' line' ) && has_key (a: opts , ' col' )
108
115
let opts.line = a: opts .line
@@ -266,6 +273,9 @@ function! s:popup_exit(winid, code)
266
273
let g: quickui #context#current = hwnd
267
274
let g: quickui #context#cursor = hwnd.index
268
275
let redrawed = 0
276
+ if has_key (hwnd.opts, ' savepos' )
277
+ let s: previous_cursor [hwnd.opts.savepos] = hwnd.index
278
+ endif
269
279
if has_key (hwnd.opts, ' callback' )
270
280
let F = function (hwnd.opts.callback)
271
281
call F (code)
@@ -491,6 +501,11 @@ function! s:nvim_create_context(textlist, opts)
491
501
let h = hwnd.height
492
502
let hwnd.index = get (a: opts , ' index' , -1 )
493
503
let hwnd.opts = deepcopy (a: opts )
504
+ if has_key (hwnd.opts, ' savepos' )
505
+ if has_key (s: previous_cursor , hwnd.opts.savepos)
506
+ let hwnd.index = get (s: previous_cursor , hwnd.opts.savepos, 0 )
507
+ endif
508
+ endif
494
509
let opts = {' width' :w , ' height' :h , ' focusable' :1 , ' style' :' minimal' }
495
510
let opts.relative = ' editor'
496
511
if has_key (a: opts , ' line' ) && has_key (a: opts , ' col' )
@@ -603,6 +618,9 @@ function! s:nvim_create_context(textlist, opts)
603
618
let g: quickui #context#code = retval
604
619
let g: quickui #context#current = hwnd
605
620
let g: quickui #context#cursor = hwnd.index
621
+ if has_key (hwnd.opts, ' savepos' )
622
+ let s: previous_cursor [hwnd.opts.savepos] = hwnd.index
623
+ endif
606
624
if has_key (hwnd.opts, ' callback' )
607
625
let F = function (hwnd.opts.callback)
608
626
call F (retval)
@@ -620,19 +638,64 @@ function! s:nvim_create_context(textlist, opts)
620
638
endfunc
621
639
622
640
641
+ " ----------------------------------------------------------------------
642
+ " reduce with file types
643
+ " ----------------------------------------------------------------------
644
+ function ! s: reduce_items (textlist)
645
+ let output = []
646
+ let state = 1
647
+ let index = 0
648
+ let limit = len (a: textlist )
649
+ for item in a: textlist
650
+ if len (item) > 0
651
+ let issep = ((item[0 ]) = ~ ' ^-\+$' )? 1 : 0
652
+ if issep != 0
653
+ if state == 0
654
+ if index + 1 < limit
655
+ let output += [item]
656
+ let state = 1
657
+ endif
658
+ endif
659
+ else
660
+ if type (item) == v: t_string
661
+ let output += [item]
662
+ let state = 0
663
+ elseif len (item) < 4
664
+ let output += [item]
665
+ let state = 0
666
+ else
667
+ for check in split (item[3 ], ' ,' )
668
+ if &ft == check
669
+ let output += [item]
670
+ let state = 0
671
+ break
672
+ endif
673
+ endfor
674
+ endif
675
+ endif
676
+ endif
677
+ let index += 1
678
+ endfor
679
+ return output
680
+ endfunc
681
+
682
+
623
683
" ----------------------------------------------------------------------
624
684
" create menu object
625
685
" ----------------------------------------------------------------------
626
686
function ! quickui#context#open (textlist, opts)
687
+ let textlist = a: textlist
688
+ if get (a: opts , ' reduce' , 0 ) != 0
689
+ let textlist = s: reduce_items (a: textlist )
690
+ endif
627
691
if g: quickui #core#has_nvim == 0
628
- return s: vim_create_context (a: textlist , a: opts )
692
+ return s: vim_create_context (textlist, a: opts )
629
693
else
630
- return s: nvim_create_context (a: textlist , a: opts )
694
+ return s: nvim_create_context (textlist, a: opts )
631
695
endif
632
696
endfunc
633
697
634
698
635
-
636
699
" ----------------------------------------------------------------------
637
700
" testing suit
638
701
" ----------------------------------------------------------------------
@@ -646,10 +709,11 @@ if 0
646
709
\ " &Save\t Ctrl+s" ,
647
710
\ " Save &As" ,
648
711
\ " Save All" ,
649
- \ " -" ,
712
+ \ " -- " ,
650
713
\ " &User Menu\t F9" ,
651
714
\ " &Dos Shell" ,
652
715
\ " ~&Time %{&undolevels? '+':'-'}" ,
716
+ \ [" S&plit" , ' help 1' , ' ' , ' vim2' ],
653
717
\ " --" ,
654
718
\ " E&xit\t Alt+x" ,
655
719
\ " &Help" ,
658
722
" let menu = quickui#context#menu_compile(lines, 1)
659
723
let opts = {' cursor' : -1 , ' line2' :' cursor+1' , ' col2' : ' cursor' , ' horizon' :1 }
660
724
" let opts.index = 2
725
+ let opts.savepos = ' f'
661
726
let opts.callback = ' MyCallback'
727
+ let opts.reduce = 1
662
728
function ! MyCallback (code)
663
729
echo " callback: " . a: code
664
730
endfunc
0 commit comments