Add text and select_text to CommandView options

This commit is contained in:
Guldoman
2022-06-02 19:30:51 +02:00
parent 6c89a3e575
commit ec58b1f0bd
6 changed files with 53 additions and 24 deletions
+6 -7
View File
@@ -229,22 +229,20 @@ local function begin_search(text, fn)
end
local function set_command_view_text()
local function get_selected_text()
local view = core.active_view
local doc = (view and view.doc) and view.doc or nil
if doc then
core.command_view:set_text(
doc:get_text(table.unpack({ doc:get_selection() })),
true
)
return doc:get_text(table.unpack({ doc:get_selection() }))
end
end
command.add(nil, {
["project-search:find"] = function()
set_command_view_text()
core.command_view:enter("Find Text In Project", {
text = get_selected_text(),
select_text = true,
submit = function(text)
text = text:lower()
begin_search(text, function(line_text)
@@ -266,8 +264,9 @@ command.add(nil, {
end,
["project-search:fuzzy-find"] = function()
set_command_view_text()
core.command_view:enter("Fuzzy Find Text In Project", {
text = get_selected_text(),
select_text = true,
submit = function(text)
begin_search(text, function(line_text)
return common.fuzzy_match(line_text, text) and 1
+7 -3
View File
@@ -689,8 +689,8 @@ command.add(function() return treeitem() ~= nil end, {
["treeview:rename"] = function()
local old_filename = treeitem().filename
local old_abs_filename = treeitem().abs_filename
core.command_view:set_text(old_filename)
core.command_view:enter("Rename", {
text = old_filename,
submit = function(filename)
filename = core.normalize_to_project_dir(filename)
local abs_filename = core.project_absolute_path(filename)
@@ -713,10 +713,12 @@ command.add(function() return treeitem() ~= nil end, {
end,
["treeview:new-file"] = function()
local text
if not is_project_folder(treeitem().abs_filename) then
core.command_view:set_text(treeitem().filename .. "/")
text = treeitem().filename .. "/"
end
core.command_view:enter("Filename", {
text = text,
submit = function(filename)
local doc_filename = core.project_dir .. PATHSEP .. filename
local file = io.open(doc_filename, "a+")
@@ -730,10 +732,12 @@ command.add(function() return treeitem() ~= nil end, {
end,
["treeview:new-folder"] = function()
local text
if not is_project_folder(treeitem().abs_filename) then
core.command_view:set_text(treeitem().filename .. "/")
text = treeitem().filename .. "/"
end
core.command_view:enter("Folder Name", {
text = text,
submit = function(filename)
local dir_path = core.project_dir .. PATHSEP .. filename
common.mkdirp(dir_path)