diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index a8819b56..b7914ece 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -278,6 +278,10 @@ local commands = { end) end, + ["doc:toggle-line-ending"] = function() + doc().crlf = not doc().crlf + end, + ["doc:save-as"] = function() if doc().filename then core.command_view:set_text(doc().filename) @@ -295,8 +299,20 @@ local commands = { end end, - ["doc:toggle-line-ending"] = function() - doc().crlf = not doc().crlf + ["doc:rename"] = function() + local old_filename = doc().filename + if not old_filename then + core.error("Cannot rename unsaved doc") + return + end + core.command_view:set_text(old_filename) + core.command_view:enter("Rename", function(filename) + doc():save(filename) + core.log("Renamed \"%s\" to \"%s\"", old_filename, filename) + if filename ~= old_filename then + os.remove(old_filename) + end + end, common.path_suggest) end, } diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 1fc48cf0..da0f9a2f 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -35,8 +35,7 @@ local function find(label, search_fn) local text = dv.doc:get_text(table.unpack(sel)) local found = false - core.command_view:set_text(text) - core.command_view.doc:set_selection(math.huge, math.huge, 1, 1) + core.command_view:set_text(text, true) core.command_view:enter(label, function(text) if found then @@ -69,12 +68,10 @@ end local function replace(kind, default, fn) - core.command_view:set_text(default) - core.command_view.doc:set_selection(math.huge, math.huge, 1, 1) + core.command_view:set_text(default, true) core.command_view:enter("Find To Replace " .. kind, function(old) - core.command_view:set_text(old) - core.command_view.doc:set_selection(math.huge, math.huge, 1, 1) + core.command_view:set_text(old, true) local s = string.format("Replace %s %q With", kind, old) core.command_view:enter(s, function(new) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index ccd8b4b4..18091808 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -70,9 +70,12 @@ function CommandView:get_text() end -function CommandView:set_text(text) +function CommandView:set_text(text, select) self.doc:remove(1, 1, math.huge, math.huge) self.doc:text_input(text) + if select then + self.doc:set_selection(math.huge, math.huge, 1, 1) + end end