diff --git a/lua/tinygit.lua b/lua/tinygit.lua index c124983..b5c1fc0 100644 --- a/lua/tinygit.lua +++ b/lua/tinygit.lua @@ -221,6 +221,10 @@ end -------------------------------------------------------------------------------- +---Saves the content of a `vim.ui.input` modal that was aborted with ``, +---so it can be restored. +local lastAbortedInputText = nil + ---If there are staged changes, commit them. ---If there aren't, add all changes (`git add -A`) and then commit. ---@param prefillMsg? string @@ -230,7 +234,11 @@ function M.smartCommit(opts, prefillMsg) vim.cmd("silent update") if not opts then opts = {} end - if not prefillMsg then prefillMsg = "" end + if not prefillMsg and not lastAbortedInputText then + prefillMsg = "" + elseif not prefillMsg and lastAbortedInputText then + prefillMsg = lastAbortedInputText + end setGitCommitAppearance() vim.ui.input({ prompt = "󰊢 Commit Message", default = prefillMsg }, function(commitMsg) @@ -249,6 +257,8 @@ function M.smartCommit(opts, prefillMsg) local stderr = fn.system { "git", "commit", "-m", newMsg } if nonZeroExit(stderr) then return end + lastAbortedInputText = nil -- empty it, so it isn't prefilled + local body = ('"%s"'):format(newMsg) if opts.push then body = body .. "\nPushing…" end notify(body, "info", "Smart-Commit")