]> git.lizzy.rs Git - micro.git/commitdiff
Relocate during replace
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 24 Mar 2020 15:33:52 +0000 (11:33 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Tue, 24 Mar 2020 15:33:52 +0000 (11:33 -0400)
Fixes #1587

internal/action/command.go
internal/display/bufwindow.go

index ec4da4848154e4a25b7c21215b2bce11dadf0be3..3fdd30a7deb4f805c525ad6a51a494cecaa8bc06 100644 (file)
@@ -762,6 +762,8 @@ func (h *BufPane) ReplaceCmd(args []string) {
                        h.Cursor.SetSelectionStart(locs[0])
                        h.Cursor.SetSelectionEnd(locs[1])
 
+                       h.Relocate()
+
                        InfoBar.YNPrompt("Perform replacement (y,n,esc)", func(yes, canceled bool) {
                                if !canceled && yes {
                                        _, nrunes := h.Buf.ReplaceRegex(locs[0], locs[1], regex, replace)
@@ -786,6 +788,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
        }
 
        h.Buf.RelocateCursors()
+       h.Relocate()
 
        var s string
        if nreplaced > 1 {
index 372b13dc92b61aa9460fd8accc198c10bb891565..f366cfe72ad8e58c4520e3502925b99a0c0d82f0 100644 (file)
@@ -139,6 +139,9 @@ func (w *BufWindow) Relocate() bool {
        ret := false
        activeC := w.Buf.GetActiveCursor()
        cy := activeC.Y
+       if activeC.HasSelection() {
+               cy = activeC.CurSelection[0].Y
+       }
        scrollmargin := int(b.Settings["scrollmargin"].(float64))
        if cy < w.StartLine+scrollmargin && cy > scrollmargin-1 {
                w.StartLine = cy - scrollmargin