diff --git a/editor.lua b/editor.lua index 58ad214..175ad54 100644 --- a/editor.lua +++ b/editor.lua @@ -234,6 +234,10 @@ function module.create(data) else current_info = cmd end + + if #open_areas == 0 and not pending_op then + current_info = current_info .. " (enter to apply)" + end return true else return false @@ -377,8 +381,12 @@ function module.create(data) end end if alt then - local areas = layout.machi_get_areas(screen, tag) - set_cmd(machi_engine.areas_to_command(areas)) + if embed_args then + set_cmd(embed_args.original_cmd or "") + else + local areas = layout.machi_get_areas(screen, tag) + set_cmd(machi_engine.areas_to_command(areas)) + end else set_cmd(current_cmd:sub(1, #current_cmd - 1)) end @@ -397,13 +405,9 @@ function module.create(data) end log(DEBUG, "restore history #" .. tostring(cmd_index) .. ":" .. data.cmds[cmd_index]) - if set_cmd(data.cmds[cmd_index]) and #open_areas == 0 then - current_info = current_info .. " (enter to save)" - end + set_cmd(data.cmds[cmd_index]) elseif #open_areas > 0 or pending_op then - if handle_key(key) and #open_areas == 0 and not pending_op then - current_info = current_info .. " (enter to apply)" - end + handle_key(key) else if key == "Return" then local alt = false diff --git a/engine.lua b/engine.lua index 439e7f7..56752b5 100644 --- a/engine.lua +++ b/engine.lua @@ -782,8 +782,9 @@ local function areas_from_command(command, workarea, minimum) return closed_areas, open_areas, pending_op ~= nil end -local function areas_to_command(areas, to_embed) - if #areas == 0 then return nil end +local function areas_to_command(areas, to_embed, root_area) + root_area = root_area or 1 + if #areas < root_area then return nil end local function shares_to_arg_str(shares) local arg_str = "" @@ -880,7 +881,7 @@ local function areas_to_command(areas, to_embed) end end - if a.parent_id then + if area_id ~= root_area then if a.expansion ~= areas[a.parent_id].expansion - 1 then r = "t"..tostring(a.expansion)..r end @@ -900,9 +901,14 @@ local function areas_to_command(areas, to_embed) return r end - local r = get_command(1) + local r = get_command(root_area) if not to_embed then - r = r:gsub("[\\c]+$", ".") + if r == "-" then + r = "." + else + -- The last . may be redundant, but it makes sure no pending op. + r = r:gsub("[\\c]+$", "").."." + end end return r end @@ -921,14 +927,15 @@ if not in_module then assert(false) end end - check_transcoded_command("t.", "-") + check_transcoded_command(".", ".") + check_transcoded_command("3t.", ".") check_transcoded_command("121h.", "h1,2,1.") check_transcoded_command("1_10,2,1h1s131v.", "h1_10,2,1-v1,3,1.") check_transcoded_command("332111w.", "w3,3,2,1,1,1.") check_transcoded_command("1310111d.", ";d1,3,1,,1,1,1.") - check_transcoded_command("dw66.", "dw6,6") - check_transcoded_command(";dw66.", ";dw6,6") - check_transcoded_command("101dw66.", ";dw6,6") + check_transcoded_command("dw66.", "dw6,6.") + check_transcoded_command(";dw66.", ";dw6,6.") + check_transcoded_command("101dw66.", ";dw6,6.") check_transcoded_command("3tdw66.", "t3;dw6,6.") print("Passed.") end diff --git a/switcher.lua b/switcher.lua index b8825e2..a74dcf7 100644 --- a/switcher.lua +++ b/switcher.lua @@ -472,11 +472,10 @@ function module.start(c, exit_keys) end elseif key == "/" and not draft_mode then local current_area = selected_area() + local original_cmd = machi.engine.areas_to_command(areas, true, current_area) areas[current_area].hole = true local prefix, suffix = machi.engine.areas_to_command( - areas, true):match("(.*)|(.*)") - print(prefix, suffix) - + areas, false):match("(.*)|(.*)") areas[current_area].hole = nil workarea = { @@ -492,6 +491,7 @@ function module.start(c, exit_keys) screen, { workarea = workarea, + original_cmd = original_cmd, cmd_prefix = prefix, cmd_suffix = suffix, }