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
+9 -4
View File
@@ -122,15 +122,16 @@ command.add(nil, {
["core:open-file"] = function()
local view = core.active_view
local text
if view.doc and view.doc.abs_filename then
local dirname, filename = view.doc.abs_filename:match("(.*)[/\\](.+)$")
if dirname then
dirname = core.normalize_to_project_dir(dirname)
local text = dirname == core.project_dir and "" or common.home_encode(dirname) .. PATHSEP
core.command_view:set_text(text)
text = dirname == core.project_dir and "" or common.home_encode(dirname) .. PATHSEP
end
end
core.command_view:enter("Open File", {
text = text,
submit = function(text)
local filename = system.absolute_path(common.home_expand(text))
core.root_view:open_doc(core.open_doc(filename))
@@ -182,10 +183,12 @@ command.add(nil, {
["core:change-project-folder"] = function()
local dirname = common.dirname(core.project_dir)
local text
if dirname then
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
text = common.home_encode(dirname) .. PATHSEP
end
core.command_view:enter("Change Project Folder", {
text = text,
submit = function(text)
local path = common.home_expand(text)
local abs_path = check_directory_path(path)
@@ -204,10 +207,12 @@ command.add(nil, {
["core:open-project-folder"] = function()
local dirname = common.dirname(core.project_dir)
local text
if dirname then
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
text = common.home_encode(dirname) .. PATHSEP
end
core.command_view:enter("Open Project", {
text = text,
submit = function(text)
local path = common.home_expand(text)
local abs_path = check_directory_path(path)
+5 -3
View File
@@ -448,13 +448,15 @@ local commands = {
["doc:save-as"] = function()
local last_doc = core.last_active_view and core.last_active_view.doc
local text
if doc().filename then
core.command_view:set_text(doc().filename)
text = doc().filename
elseif last_doc and last_doc.filename then
local dirname, filename = core.last_active_view.doc.abs_filename:match("(.*)[/\\](.+)$")
core.command_view:set_text(core.normalize_to_project_dir(dirname) .. PATHSEP)
text = core.normalize_to_project_dir(dirname) .. PATHSEP
end
core.command_view:enter("Save As", {
text = text,
submit = function(filename)
save(common.home_expand(filename))
end,
@@ -482,8 +484,8 @@ local commands = {
core.error("Cannot rename unsaved doc")
return
end
core.command_view:set_text(old_filename)
core.command_view:enter("Rename", {
text = old_filename,
submit = function(filename)
save(common.home_expand(filename))
core.log("Renamed \"%s\" to \"%s\"", old_filename, filename)
+6 -4
View File
@@ -58,10 +58,11 @@ local function find(label, search_fn)
local text = last_view.doc:get_text(table.unpack(last_sel))
found_expression = false
core.command_view:set_text(text, true)
core.status_view:show_tooltip(get_find_tooltip())
core.command_view:enter(label, {
text = text,
select_text = true,
show_suggestions = false,
submit = function(text, item)
insert_unique(core.previous_find, text)
@@ -91,17 +92,18 @@ end
local function replace(kind, default, fn)
core.command_view:set_text(default, true)
core.status_view:show_tooltip(get_find_tooltip())
core.command_view:enter("Find To Replace " .. kind, {
text = default,
select_text = true,
show_suggestions = false,
submit = function(old)
insert_unique(core.previous_find, old)
core.command_view:set_text(old, true)
local s = string.format("Replace %s %q With", kind, old)
core.command_view:enter(s, {
text = old,
select_text = true,
show_suggestions = false,
submit = function(new)
core.status_view:remove_tooltip()