From 490af7bf6d10daa3daa97d3a665d7335800c1f74 Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 13 Nov 2019 10:31:55 +0800 Subject: [PATCH] opt vim.favor --- etc/conf/auto.vim | 21 ++++++++++++++++++--- src/contexts/ssh/ssh.go | 2 +- src/examples/code/code.go | 18 ++++++++++++++++++ src/plugin/vim/index.shy | 18 +++--------------- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/etc/conf/auto.vim b/etc/conf/auto.vim index 8a590e2b..121fcaaa 100644 --- a/etc/conf/auto.vim +++ b/etc/conf/auto.vim @@ -1,7 +1,9 @@ let ctx_url = (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9095") . "/code/vim" let ctx_head = "Content-Type: application/json" -let ctx_sid = "" +if !exists("g:ctx_sid") + let ctx_sid = "" +end fun! ShyPost(arg) let a:arg["buf"] = bufname("%") @@ -39,6 +41,14 @@ fun! ShyCheck(target) endif elseif a:target == "favor" cexpr ShyPost({"cmd": "favor"}) + elseif a:target == "favors" + let msg = json_decode(ShyPost({"cmd": "favors"})) + let i = 0 + for i in range(len(msg["tab"])) + tabnew + lexpr msg["fix"][i] + lopen + endfor elseif a:target == "cache" call ShySync("bufs") call ShySync("regs") @@ -74,11 +84,15 @@ fun! Shy(action, target) endif endfun +let favor_tab = "" +let favor_note = "" fun! ShyFavor(note) if a:note == "" call ShyPost({"cmd": "favor", "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]}) else - call ShyPost({"cmd": "favor", "note": input("note: "), "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]}) + let g:favor_tab = input("tab: ", g:favor_tab) + let g:favor_note = input("note: ", g:favor_note) + call ShyPost({"cmd": "favor", "tab": g:favor_tab, "note": g:favor_note, "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]}) endif endfun @@ -104,7 +118,8 @@ call ShySync("tags") " call ShySync("fixs") " nnoremap :call ShyCheck("cache") -nnoremap :call ShyCheck("favor") +" nnoremap :call ShyCheck("favor") +nnoremap :call ShyCheck("favors") nnoremap F :call ShyFavor("note") nnoremap f :call ShyFavor("") diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index b3a73545..d492267a 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -410,7 +410,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", switch arg[0] { case "show": - if arg[1] == "" { + if len(arg) > 1 && arg[1] == "" { arg = arg[:1] } switch len(arg) { diff --git a/src/examples/code/code.go b/src/examples/code/code.go index 83e12529..a8f0ca92 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -831,12 +831,30 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "time"}, m.Time()) m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "status"}, "logout") + case "favors": + m.Option("river", m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "river"})) + table := m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "table"}) + m.Log("info", "favor: %v table: %v", m.Option("river"), table) + + data := map[string][]string{} + m.Cmd("ssh.data", "show", table).Table(func(index int, value map[string]string) { + data[value["tab"]] = append(data[value["tab"]], + fmt.Sprintf("%v:%v:0:(%v): %v\n", value["file"], value["line"], value["note"], value["word"])) + }) + + for k, v := range data { + m.Push("tab", k) + m.Push("fix", strings.Join(v, "\n")) + } + return case "favor": m.Option("river", m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "river"})) table := m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "table"}) + m.Log("info", "favor: %v table: %v", m.Option("river"), table) if m.Options("line") { m.Cmd("ssh.data", "insert", table, + "tab", m.Option("tab"), "note", m.Option("note"), "word", m.Option("arg"), "file", m.Option("buf"), "line", m.Option("line"), "col", m.Option("col"), ) diff --git a/src/plugin/vim/index.shy b/src/plugin/vim/index.shy index 7951fbe8..6858d2d3 100644 --- a/src/plugin/vim/index.shy +++ b/src/plugin/vim/index.shy @@ -1,27 +1,15 @@ fun tips "便签" private \ - select "" name "action" values "show" values "insert" values "update" \ text "tip" name table imports plugin_vim_table action auto \ - text "" name index imports plugin_view_tip_id view tiny \ - text "" name file imports plugin_vim_file view long \ - text "" name line imports plugin_vim_line view tiny \ - text "" name word imports plugin_vim_word view long \ - textarea "" name note \ + text "" name index imports plugin_tip_id view tiny action auto \ feature detail "修改" "复制" "下载" \ exports vim_table table "" tip_id id "" vim_file file "" vim_line line "" vim_word word "" \ button "记录" action auto - if $1 == "show" - copy skip ssh.data _ _ - end - if $1 == "insert" - copy skip ssh.data insert $2 file $4 line $5 word $6 note $7 - end - if $1 == "update" - copy skip ssh.data update $2 $3 file $4 line $5 word $6 note $7 - end if $2 == "modify" copy skip ssh.data update $table $1 $3 $4 + else + copy ssh.data show end end