Skip to content

Commit 8c0e0fa

Browse files
authored
Make textfilter work with multicursors (zyedidia#3511)
As requested in [1] and [2], change the `textfilter` command behavior to apply the filter to the selections of all cursors, not just the 1st one. [1] zyedidia#3505 [2] zyedidia#3510
1 parent f293f98 commit 8c0e0fa

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

internal/action/command.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,25 @@ func (h *BufPane) TextFilterCmd(args []string) {
139139
InfoBar.Error("usage: textfilter arguments")
140140
return
141141
}
142-
sel := h.Cursor.GetSelection()
143-
if len(sel) == 0 {
144-
h.Cursor.SelectWord()
145-
sel = h.Cursor.GetSelection()
146-
}
147-
var bout, berr bytes.Buffer
148-
cmd := exec.Command(args[0], args[1:]...)
149-
cmd.Stdin = strings.NewReader(string(sel))
150-
cmd.Stderr = &berr
151-
cmd.Stdout = &bout
152-
err := cmd.Run()
153-
if err != nil {
154-
InfoBar.Error(err.Error() + " " + berr.String())
155-
return
142+
for _, c := range h.Buf.GetCursors() {
143+
sel := c.GetSelection()
144+
if len(sel) == 0 {
145+
c.SelectWord()
146+
sel = c.GetSelection()
147+
}
148+
var bout, berr bytes.Buffer
149+
cmd := exec.Command(args[0], args[1:]...)
150+
cmd.Stdin = strings.NewReader(string(sel))
151+
cmd.Stderr = &berr
152+
cmd.Stdout = &bout
153+
err := cmd.Run()
154+
if err != nil {
155+
InfoBar.Error(err.Error() + " " + berr.String())
156+
return
157+
}
158+
c.DeleteSelection()
159+
h.Buf.Insert(c.Loc, bout.String())
156160
}
157-
h.Cursor.DeleteSelection()
158-
h.Buf.Insert(h.Cursor.Loc, bout.String())
159161
}
160162

161163
// TabMoveCmd moves the current tab to a given index (starts at 1). The

0 commit comments

Comments
 (0)