mirror of
https://github.com/Hopiu/micro.git
synced 2026-03-16 22:10:26 +00:00
Merge
This commit is contained in:
commit
c44ccb8cc7
5 changed files with 29 additions and 22 deletions
|
|
@ -23,12 +23,9 @@ func shouldContinue() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if len(text) <= 1 {
|
||||
// default continue
|
||||
return true
|
||||
}
|
||||
text = strings.TrimRight(text, "\r\n")
|
||||
|
||||
return strings.ToLower(text)[0] == 'y'
|
||||
return len(text) == 0 || strings.ToLower(text)[0] == 'y'
|
||||
}
|
||||
|
||||
// CleanConfig performs cleanup in the user's configuration directory
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
|
@ -807,7 +810,7 @@ func (h *BufPane) SaveAs() bool {
|
|||
func (h *BufPane) saveBufToFile(filename string, action string, callback func()) bool {
|
||||
err := h.Buf.SaveAs(filename)
|
||||
if err != nil {
|
||||
if strings.HasSuffix(err.Error(), "permission denied") {
|
||||
if errors.Is(err, fs.ErrPermission) {
|
||||
saveWithSudo := func() {
|
||||
err = h.Buf.SaveAsWithSudo(filename)
|
||||
if err != nil {
|
||||
|
|
@ -824,12 +827,15 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
|
|||
if h.Buf.Settings["autosu"].(bool) {
|
||||
saveWithSudo()
|
||||
} else {
|
||||
InfoBar.YNPrompt("Permission denied. Do you want to save this file using sudo? (y,n)", func(yes, canceled bool) {
|
||||
if yes && !canceled {
|
||||
saveWithSudo()
|
||||
h.completeAction(action)
|
||||
}
|
||||
})
|
||||
InfoBar.YNPrompt(
|
||||
fmt.Sprintf("Permission denied. Do you want to save this file using %s? (y,n)", config.GlobalSettings["sucmd"].(string)),
|
||||
func(yes, canceled bool) {
|
||||
if yes && !canceled {
|
||||
saveWithSudo()
|
||||
h.completeAction(action)
|
||||
}
|
||||
},
|
||||
)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
|
|||
}
|
||||
|
||||
if readonly && prompt != nil {
|
||||
prompt.Message("Warning: file is readonly - sudo will be attempted when saving")
|
||||
prompt.Message(fmt.Sprintf("Warning: file is readonly - %s will be attempted when saving", config.GlobalSettings["sucmd"].(string)))
|
||||
// buf.SetOptionNative("readonly", true)
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -60,13 +60,11 @@ ft["zig"] = "// %s"
|
|||
ft["zscript"] = "// %s"
|
||||
ft["zsh"] = "# %s"
|
||||
|
||||
function onBufferOpen(buf)
|
||||
if buf.Settings["commenttype"] == nil then
|
||||
if ft[buf.Settings["filetype"]] ~= nil then
|
||||
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
|
||||
else
|
||||
buf.Settings["commenttype"] = "# %s"
|
||||
end
|
||||
function updateCommentType(buf)
|
||||
if ft[buf.Settings["filetype"]] ~= nil and ft[buf.Settings["filetype"]] ~= nil then
|
||||
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
|
||||
elseif buf.Settings["commenttype"] == nil then
|
||||
buf.Settings["commenttype"] = "# %s"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -79,6 +77,8 @@ function isCommented(bp, lineN, commentRegex)
|
|||
end
|
||||
|
||||
function commentLine(bp, lineN)
|
||||
updateCommentType(bp.Buf)
|
||||
|
||||
local line = bp.Buf:Line(lineN)
|
||||
local commentType = bp.Buf.Settings["commenttype"]
|
||||
local sel = -bp.Cursor.CurSelection
|
||||
|
|
@ -100,6 +100,8 @@ function commentLine(bp, lineN)
|
|||
end
|
||||
|
||||
function uncommentLine(bp, lineN, commentRegex)
|
||||
updateCommentType(bp.Buf)
|
||||
|
||||
local line = bp.Buf:Line(lineN)
|
||||
local commentType = bp.Buf.Settings["commenttype"]
|
||||
local sel = -bp.Cursor.CurSelection
|
||||
|
|
@ -149,6 +151,8 @@ function toggleCommentSelection(bp, startLine, endLine, commentRegex)
|
|||
end
|
||||
|
||||
function comment(bp, args)
|
||||
updateCommentType(bp.Buf)
|
||||
|
||||
local commentType = bp.Buf.Settings["commenttype"]
|
||||
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)"):gsub("%s+", "%s*")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue