From 6d28cf285f9944eb26c7ed0efcce558521b51cb9 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 17 Sep 2026 14:14:26 +0200 Subject: editing one form no longer takes its neighbour with it A form's span was whole lines, which is wrong the moment two forms share one. Delete: "(exclude A) (exclude B)" on one line, delete the first, both went. The dialog named one. The file still parsed, the live check said no errors and Save lit, so an exclusion could disappear silently and the next run would sort the files it had been protecting. Clear a setting: the same shape, and the Settings window walked into it itself - it writes "(defaults\n (case ignore))", so the closing paren of defaults sits on the setting's line, and putting that setting back to "default" deleted the line and broke the file it had just written. Every later change then silently reverted until Settings was reopened. A hand-written "(defaults (case ignore) (fold yes))" lost fold the same way, and that one still loaded, so it was saveable. Both now take the whole line only when the line holds nothing else, and otherwise take the form and the spaces after it. One helper, used by the main file and by a directory's settings alike. --- gui/internal/model/settings.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'gui/internal/model/settings.go') diff --git a/gui/internal/model/settings.go b/gui/internal/model/settings.go index 5763d68..6fa7156 100644 --- a/gui/internal/model/settings.go +++ b/gui/internal/model/settings.go @@ -51,8 +51,7 @@ func (r *Rules) SetSetting(head, args string) error { } switch { case node != nil && args == "": - start, end := r.lineSpan(node) - r.Text = join(r.Text[:start], r.Text[end:]) + r.Text = clearForm(r.Text, node.Pos.Offset, node.End.Offset) case node != nil: r.Text = r.Text[:node.Pos.Offset] + "(" + head + " " + args + ")" + r.Text[node.End.Offset:] default: @@ -118,12 +117,6 @@ func (r *Rules) headerEnd() (int, error) { return at, nil } -// lineSpan is the whole line a setting is written on, so clearing it takes -// the comment that trails it rather than leaving it to dangle. -func (r *Rules) lineSpan(n *sexp.Node) (start, end int) { - return lineStart(r.Text, n.Pos.Offset), lineEnd(r.Text, n.End.Offset) -} - // argsOf is a form's arguments exactly as the file writes them. func argsOf(n *sexp.Node, text string) string { if len(n.Children) < 2 { -- cgit v1.3