From 54de21d8b95655cbb7709d2040c77a40d3242843 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Tue, 4 Oct 2022 12:22:51 +0800 Subject: [PATCH] opt some --- frame.js | 7 ++-- lib/user.js | 1 + plugin/input/key.js | 1 + plugin/local/code/inner.js | 5 ++- plugin/local/code/inner/favor.js | 2 +- plugin/local/code/inner/search.js | 62 ++++++------------------------- plugin/state.js | 3 +- proto.js | 1 + 8 files changed, 26 insertions(+), 56 deletions(-) diff --git a/frame.js b/frame.js index 102d85c5..e0d041d6 100644 --- a/frame.js +++ b/frame.js @@ -99,9 +99,9 @@ Volcanos(chat.ONENGINE, {help: "搜索引擎", _init: function(can, meta, list, name = can.base.trimPrefix(name, "can.") var type = html.TEXT; command.list = can.core.List(command.list, function(item) { switch (typeof item) { - case lang.STRING: return can.core.SplitInput(item) - case lang.OBJECT: return type = item.type||type, item - } + case lang.STRING: item = can.core.SplitInput(item, type) + } type = item.type + return item }), command.can = can, arguments.callee.meta[name] = command }), listen: shy("监听事件", function(can, name, cb) { @@ -409,6 +409,7 @@ Volcanos(chat.ONAPPEND, {help: "渲染引擎", _init: function(can, meta, list, } return run([ctx.ACTION, target.name]) } + can.sup && can.sup.onexport && can.sup.onexport.record && can.sup.onexport.record(can.sup, line) if (key == mdb.HASH && can.user.mod.isDiv) { return can.user.jumps("/chat/div/"+value) } if (can.sup.onaction.change(event, can.sup, key, event.target.innerText).length == 0) { can.sup && can.sup._item_click && can.sup._item_click(value, key) diff --git a/lib/user.js b/lib/user.js index a4161fd7..2fca70db 100644 --- a/lib/user.js +++ b/lib/user.js @@ -273,6 +273,7 @@ Volcanos("user", {help: "用户操作", info: {}, agent: { need[item.name] = item.need item._init = function(target) { + item._enter = function(event) { action.submit(event, can, "submit") } item.run = function(event, cmds, cb) { var _msg = can.request(event, {_handle: ice.TRUE, action: msg.Option(html.ACTION)}, msg, can.Option()) can.page.Select(can, ui.table, html.OPTION_ARGS, function(item) { diff --git a/plugin/input/key.js b/plugin/input/key.js index cfa3a051..64ac36af 100644 --- a/plugin/input/key.js +++ b/plugin/input/key.js @@ -46,6 +46,7 @@ Volcanos(chat.ONFIGURE, {help: "控件详情", key: { }, onkeydown: function(event, can, meta, cb, target, last) { switch (event.key) { + case "Enter": meta._enter && meta._enter(event); break case "Escape": target._can? target._can.close(): target.blur(); return case "Tab": target._can && target._can.close(); return case "n": diff --git a/plugin/local/code/inner.js b/plugin/local/code/inner.js index c62aafda..bb3150cd 100644 --- a/plugin/local/code/inner.js +++ b/plugin/local/code/inner.js @@ -421,6 +421,9 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, msg, cb, tar }, toolkit: function(can, meta, cb) { meta.msg = true can.onimport.plug(can, meta, can.ui.toolkit.output, function(sub) { + sub.onexport.record = function(sub, line) { if (!line.file && !line.line) { return } + can.onimport.tabview(can, line.path||can.Option(nfs.PATH), can.base.trimPrefix(line.file, nfs.PWD)||can.Option(nfs.FILE), parseInt(line.line)), can.current.scroll(can.current.scroll()-4) + } sub.onimport.size(sub, can.ConfHeight()/2, can.ConfWidth() - can.ui.profile.offsetWidth, true) can._status.appendChild(sub._legend), sub._legend.onclick = function(event) { if (can.page.Select(can, can._status, ice.PT+html.SELECT)[0] == event.target) { @@ -437,7 +440,7 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, msg, cb, tar }) }, exts: function(can, url, cb) { - can.require([url], function() {}, function(can, name, sub) { name == chat.ONIMPORT && sub._init(can, can.base.ParseURL(sub._path), function(sub) { + can.require([url], function() {}, function(can, name, sub) { sub._init(can, sub, function(sub) { can.extentions[url.split("?")[0]] = sub, can.base.isFunc(cb)? cb(sub): sub.select() }) }) }, diff --git a/plugin/local/code/inner/favor.js b/plugin/local/code/inner/favor.js index cdb2d0c8..9d947419 100644 --- a/plugin/local/code/inner/favor.js +++ b/plugin/local/code/inner/favor.js @@ -1,4 +1,4 @@ -Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, args, cb) { +Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, cb) { can.onimport.toolkit(can, {index: "web.code.favor"}, function(sub) { sub.run = function(event, cmds, cb) { var msg = can.request(event) if (can.misc.runAction(can, msg, cmds, cb, kit.Dict( diff --git a/plugin/local/code/inner/search.js b/plugin/local/code/inner/search.js index d6a4a5f7..65be7f38 100644 --- a/plugin/local/code/inner/search.js +++ b/plugin/local/code/inner/search.js @@ -1,55 +1,17 @@ -Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, args, cb) { var history = []; const SEARCH = "can.code.inner.search" - function show(msg, word) { if (!msg) { return } history.push(msg); var sub = msg._can; sub.Option("word", word||msg._word) - !sub.page.ClassList.has(sub, sub._legend, "select") && can.ui.search.select() +Volcanos(chat.ONPLUGIN, {help: "导入数据", _init: function(can, sub, cb) { const SEARCH = "can.code.inner.search"; var history = [] + can.onengine.plugin(can, SEARCH, shy("搜索", {}, ["word=main", "filter", "grep:button", "make", "history", "last"], function(can, msg, cmds, cb) { can.misc.runAction(can, msg, cmds, cb, kit.Dict( + nfs.GREP, function(cmds) { can.runAction(msg, nfs.GREP, [cmds[0]], function(msg) { show(msg, cmds[0]) }) }, + "history", function(cmds) { can.core.List(can.history, function(item) { msg.PushRecord(item) }), show(msg) }, + "last", function(cmds) { history.pop(), show(history.pop()) }, + )) })), can.onimport.toolkit(can, {index: SEARCH}, function(sub) { can.ui.search = sub, can.base.isFunc(cb) && cb(sub) }) + + function show(msg, word) { if (!msg) { return } history.push(msg); var sub = msg._can + sub.onimport.size(sub, can.ConfHeight()/4, can.ConfWidth()-can.ui.project.offsetWidth, true) sub.onmotion.clear(sub), sub.onappend.table(sub, msg, function(value, key, index, line) { - return {text: ["", html.TD], list: [{text: [can.page.replace(can, value, ice.PWD, ""), html.DIV]}], onclick: function(event) { - line.line && can.onimport.tabview(can, line.path||can.Option(nfs.PATH), line.file.replace(ice.PWD, ""), parseInt(line.line)) + return {text: ["", html.TD], list: [{text: [can.base.trimPrefix(value, nfs.PWD), html.DIV]}], onclick: function(event) { if (!line.line) { return } + can.onimport.tabview(can, line.path||can.Option(nfs.PATH), can.base.trimPrefix(line.file, nfs.PWD)||can.Option(nfs.FILE), parseInt(line.line)), can.current.scroll(can.current.scroll()-4) }} }, sub._output), sub.onappend.board(sub, msg.Result()), sub.onappend._status(sub, msg.Option(ice.MSG_STATUS)) + !sub.page.ClassList.has(sub, sub._legend, html.SELECT) && sub.select(), sub.Focus(), sub.Option("word", word||msg._word||"") } - can.onengine.plugin(can, SEARCH, shy("搜索", {}, [ - {type: html.TEXT, name: "word", value: cli.MAIN, onkeydown: function(event, can) { - can.onmotion.selectTable(event, can.sup, event.target, function(tr) { - can.page.Select(can, tr, html.TD, function(td, index) { index == 0 && td.click() }) - tr.scrollIntoView(), can._output.scrollTop -= 60 - }) - if (event.key == lang.ENTER) { can.sup.Update(event, [ctx.ACTION, event.ctrlKey? nfs.GREP: nfs.TAGS, can.sup.Option("word")]) } - if (event.key == lang.ESCAPE) { event.target.blur() } - }}, - {type: html.TEXT, name: "filter", value: "", onkeydown: function(event, can) { - can.onmotion.selectInputTable(event, can.sup, null, event.target) - if (event.key == lang.ENTER) { can.sup.Update(event, [ctx.ACTION, event.ctrlKey? nfs.GREP: nfs.TAGS, can.sup.Option("word")]) } - if (event.key == lang.ESCAPE) { event.target.blur() } - }}, - {type: html.BUTTON, name: nfs.TAGS}, - {type: html.BUTTON, name: nfs.GREP}, - {type: html.BUTTON, name: cli.MAKE}, - {type: html.BUTTON, name: "history"}, - {type: html.BUTTON, name: "last", _trans: "返回"}, - ], function(can, msg, cmds, cb) { if (can.misc.runAction(can, msg, cmds, cb, kit.Dict( - "history", function(cmds) { - can.core.List(can.history, function(item) { - msg.Push(nfs.FILE, item.file) - msg.Push(nfs.LINE, item.line) - msg.Push(mdb.TEXT, item.text) - }) - show(msg) - }, - nfs.TAGS, function(cmds) { msg.Option(kit.Dict(ice.MSG_HANDLE, ice.TRUE, ice.MSG_FIELDS, "path,file,line,text")) - can.runAction(msg, mdb.SEARCH, [can.parse, cmds[0], can.Option(nfs.PATH)], function(msg) { var sub = msg._can - can.page.style(can, sub._output, html.MAX_HEIGHT, can.ConfHeight()/4), show(msg, msg._word = cmds[0]) - can.page.ClassList.has(sub, sub._target, html.SELECT) || sub._legend.click() - can.onmotion.focus(can, msg._can._inputs["word"]._target) - }) - }, - nfs.GREP, function(cmds) { msg.Option(kit.Dict(ice.MSG_HANDLE, ice.TRUE, ice.MSG_FIELDS, "file,line,text", nfs.PATH, can.Option(nfs.PATH))) - can.runAction(msg, nfs.GREP, [cmds[0]], function(msg) { var sub = msg._can - can.page.style(can, sub._output, html.MAX_HEIGHT, can.ConfHeight()/4), show(msg, msg._word = cmds[0]) - can.page.ClassList.has(sub, sub._target, html.SELECT) || sub._legend.click() - can.onmotion.focus(can, msg._can._inputs["word"]._target) - }) - }, - "last", function(cmds) { history.pop(), show(history.pop()) }, - ))) { return } can.run(msg, cmds, function(msg) { show(msg) }, true) })) - can.onimport.toolkit(can, {index: SEARCH}, function(sub) { can.ui.search = sub, can.ui.search._show = show, can.base.isFunc(cb) && cb(sub) }) }}) diff --git a/plugin/state.js b/plugin/state.js index de11c436..535a78e1 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -232,5 +232,6 @@ Volcanos(chat.ONACTION, {help: "交互操作", list: [ }) Volcanos(chat.ONEXPORT, {help: "导出数据", actionHeight: function(can) { return can._action.style.display == html.NONE || can._action.innerHTML == ""? 0: html.ACTION_HEIGHT }, - statusHeight: function(can) { return can._status.style.display == html.NONE || can._status.innerHTML == "" || can._status.offsetHeight == 0? 0: html.ACTION_HEIGHT } + statusHeight: function(can) { return can._status.style.display == html.NONE || can._status.innerHTML == "" || can._status.offsetHeight == 0? 0: html.ACTION_HEIGHT }, + record: function(can, line) {}, }) diff --git a/proto.js b/proto.js index 0fa879c4..c8c9dd92 100644 --- a/proto.js +++ b/proto.js @@ -83,6 +83,7 @@ var cli = { SHOW: "show", FULL: "full", } var nfs = { + PWD: "./", ZML: "zml", IML: "iml", TXT: "txt", HTML: "html", CSS: "css", JS: "js", GO: "go", SH: "sh", CSV: "csv", JSON: "json", PATH: "path", FILE: "file", LINE: "line", SIZE: "size",