From e94096cae200817d8b26513cbb620afe198173dc Mon Sep 17 00:00:00 2001 From: Hemming Svensson Date: Fri, 23 Jan 2026 07:46:32 +0100 Subject: [PATCH 1/2] feat(textfilter): Implement textfiltermode option that can be set to keep-selection --- internal/action/command.go | 15 ++++++++++++++- internal/config/settings.go | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/action/command.go b/internal/action/command.go index 7bbfe131d..d07a2ae85 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -141,6 +141,9 @@ func (h *BufPane) TextFilterCmd(args []string) { InfoBar.Error("usage: textfilter arguments") return } + + keepSelection := h.Buf.Settings["textfiltermode"].(string) == "keep-selection" + for _, c := range h.Buf.GetCursors() { sel := c.GetSelection() if len(sel) == 0 { @@ -158,7 +161,17 @@ func (h *BufPane) TextFilterCmd(args []string) { return } c.DeleteSelection() - h.Buf.Insert(c.Loc, bout.String()) + insertStart := c.Loc + insertedText := bout.String() + h.Buf.Insert(c.Loc, insertedText) + + if keepSelection { + charCount := util.CharacterCountInString(insertedText) + insertEnd := insertStart.Move(charCount, h.Buf) + c.SetSelectionStart(insertStart) + c.SetSelectionEnd(insertEnd) + c.Loc = insertEnd + } } } diff --git a/internal/config/settings.go b/internal/config/settings.go index b7097087a..1a33d477b 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -36,6 +36,7 @@ var optionValidators = map[string]optionValidator{ "scrollmargin": validateNonNegativeValue, "scrollspeed": validateNonNegativeValue, "tabsize": validatePositiveValue, + "textfiltermode": validateChoice, "truecolor": validateChoice, } @@ -47,6 +48,7 @@ var OptionChoices = map[string][]string{ "matchbracestyle": {"underline", "highlight"}, "multiopen": {"tab", "hsplit", "vsplit"}, "reload": {"prompt", "auto", "disabled"}, + "textfiltermode": {"drop-selection", "keep-selection"}, "truecolor": {"auto", "on", "off"}, } @@ -102,6 +104,7 @@ var defaultCommonSettings = map[string]any{ "tabmovement": false, "tabsize": float64(4), "tabstospaces": false, + "textfiltermode": "drop-selection", "truecolor": "auto", "useprimary": true, "wordwrap": false, From 34b0794a1bb8725b2d5d746f3ee746be2647ef46 Mon Sep 17 00:00:00 2001 From: Hemming Svensson Date: Sat, 24 Jan 2026 07:54:58 +0100 Subject: [PATCH 2/2] feat: Introduce never-select, keep-selection, always-select --- internal/action/command.go | 10 +++++++--- internal/config/settings.go | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index d07a2ae85..814697ba5 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -142,11 +142,12 @@ func (h *BufPane) TextFilterCmd(args []string) { return } - keepSelection := h.Buf.Settings["textfiltermode"].(string) == "keep-selection" + textFilterMode := h.Buf.Settings["textfiltermode"].(string) for _, c := range h.Buf.GetCursors() { sel := c.GetSelection() - if len(sel) == 0 { + hadSelection := len(sel) > 0 + if !hadSelection { c.SelectWord() sel = c.GetSelection() } @@ -165,7 +166,10 @@ func (h *BufPane) TextFilterCmd(args []string) { insertedText := bout.String() h.Buf.Insert(c.Loc, insertedText) - if keepSelection { + shouldSelect := textFilterMode == "always-select" || + (textFilterMode == "keep-selection" && hadSelection) + + if shouldSelect { charCount := util.CharacterCountInString(insertedText) insertEnd := insertStart.Move(charCount, h.Buf) c.SetSelectionStart(insertStart) diff --git a/internal/config/settings.go b/internal/config/settings.go index 1a33d477b..9a5a20a3b 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -48,7 +48,7 @@ var OptionChoices = map[string][]string{ "matchbracestyle": {"underline", "highlight"}, "multiopen": {"tab", "hsplit", "vsplit"}, "reload": {"prompt", "auto", "disabled"}, - "textfiltermode": {"drop-selection", "keep-selection"}, + "textfiltermode": {"never-select", "keep-selection", "always-select"}, "truecolor": {"auto", "on", "off"}, } @@ -104,7 +104,7 @@ var defaultCommonSettings = map[string]any{ "tabmovement": false, "tabsize": float64(4), "tabstospaces": false, - "textfiltermode": "drop-selection", + "textfiltermode": "keep-selection", "truecolor": "auto", "useprimary": true, "wordwrap": false,