@@ -500,7 +500,7 @@ func (h *BufPane) paragraphPrevious() {
500500 }
501501 // Find the first empty line
502502 for ; line > 0 ; line -- {
503- if len (h .Buf .LineBytes (line )) == 0 && line != h . Cursor . Y {
503+ if len (h .Buf .LineBytes (line )) == 0 {
504504 h .Cursor .X = 0
505505 h .Cursor .Y = line
506506 break
@@ -522,7 +522,7 @@ func (h *BufPane) paragraphNext() {
522522 }
523523 // Find the first empty line
524524 for ; line < h .Buf .LinesNum (); line ++ {
525- if len (h .Buf .LineBytes (line )) == 0 && line != h . Cursor . Y {
525+ if len (h .Buf .LineBytes (line )) == 0 {
526526 h .Cursor .X = 0
527527 h .Cursor .Y = line
528528 break
@@ -534,23 +534,29 @@ func (h *BufPane) paragraphNext() {
534534 }
535535}
536536
537- // ParagraphPrevious moves the cursor to the first empty line that comes before the paragraph closest to the cursor, or beginning of the buffer if there isn't a paragraph
537+ // ParagraphPrevious moves the cursor to the first empty line that comes before
538+ // the paragraph closest to the cursor, or beginning of the buffer if there
539+ // isn't a paragraph
538540func (h * BufPane ) ParagraphPrevious () bool {
539541 h .Cursor .Deselect (true )
540542 h .paragraphPrevious ()
541543 h .Relocate ()
542544 return true
543545}
544546
545- // ParagraphNext moves the cursor to the first empty line that comes after the paragraph closest to the cursor, or end of the buffer if there isn't a paragraph
547+ // ParagraphNext moves the cursor to the first empty line that comes after the
548+ // paragraph closest to the cursor, or end of the buffer if there isn't a
549+ // paragraph
546550func (h * BufPane ) ParagraphNext () bool {
547551 h .Cursor .Deselect (true )
548552 h .paragraphNext ()
549553 h .Relocate ()
550554 return true
551555}
552556
553- // SelectToParagraphPrevious selects to the first empty line that comes before the paragraph closest to the cursor, or beginning of the buffer if there isn't a paragraph
557+ // SelectToParagraphPrevious selects to the first empty line that comes before
558+ // the paragraph closest to the cursor, or beginning of the buffer if there
559+ // isn't a paragraph
554560func (h * BufPane ) SelectToParagraphPrevious () bool {
555561 if ! h .Cursor .HasSelection () {
556562 h .Cursor .OrigSelection [0 ] = h .Cursor .Loc
@@ -561,7 +567,9 @@ func (h *BufPane) SelectToParagraphPrevious() bool {
561567 return true
562568}
563569
564- // SelectToParagraphNext selects to the first empty line that comes after the paragraph closest to the cursor, or end of the buffer if there isn't a paragraph
570+ // SelectToParagraphNext selects to the first empty line that comes after the
571+ // paragraph closest to the cursor, or end of the buffer if there isn't a
572+ // paragraph
565573func (h * BufPane ) SelectToParagraphNext () bool {
566574 if ! h .Cursor .HasSelection () {
567575 h .Cursor .OrigSelection [0 ] = h .Cursor .Loc
@@ -1109,12 +1117,27 @@ func (h *BufPane) ToggleHighlightSearch() bool {
11091117
11101118// UnhighlightSearch unhighlights all instances of the last used search term
11111119func (h * BufPane ) UnhighlightSearch () bool {
1120+ if ! h .Buf .HighlightSearch {
1121+ return false
1122+ }
11121123 h .Buf .HighlightSearch = false
11131124 return true
11141125}
11151126
1127+ // ResetSearch resets the last used search term
1128+ func (h * BufPane ) ResetSearch () bool {
1129+ if h .Buf .LastSearch != "" {
1130+ h .Buf .LastSearch = ""
1131+ return true
1132+ }
1133+ return false
1134+ }
1135+
11161136// FindNext searches forwards for the last used search term
11171137func (h * BufPane ) FindNext () bool {
1138+ if h .Buf .LastSearch == "" {
1139+ return false
1140+ }
11181141 // If the cursor is at the start of a selection and we search we want
11191142 // to search from the end of the selection in the case that
11201143 // the selection is a search result in which case we wouldn't move at
@@ -1141,6 +1164,9 @@ func (h *BufPane) FindNext() bool {
11411164
11421165// FindPrevious searches backwards for the last used search term
11431166func (h * BufPane ) FindPrevious () bool {
1167+ if h .Buf .LastSearch == "" {
1168+ return false
1169+ }
11441170 // If the cursor is at the end of a selection and we search we want
11451171 // to search from the beginning of the selection in the case that
11461172 // the selection is a search result in which case we wouldn't move at
@@ -1189,15 +1215,19 @@ func (h *BufPane) DiffPrevious() bool {
11891215
11901216// Undo undoes the last action
11911217func (h * BufPane ) Undo () bool {
1192- h .Buf .Undo ()
1218+ if ! h .Buf .Undo () {
1219+ return false
1220+ }
11931221 InfoBar .Message ("Undid action" )
11941222 h .Relocate ()
11951223 return true
11961224}
11971225
11981226// Redo redoes the last action
11991227func (h * BufPane ) Redo () bool {
1200- h .Buf .Redo ()
1228+ if ! h .Buf .Redo () {
1229+ return false
1230+ }
12011231 InfoBar .Message ("Redid action" )
12021232 h .Relocate ()
12031233 return true
@@ -1596,10 +1626,9 @@ func (h *BufPane) ToggleRuler() bool {
15961626 return true
15971627}
15981628
1599- // ClearStatus clears the messenger bar
1629+ // ClearStatus clears the infobar. It is an alias for ClearInfo.
16001630func (h * BufPane ) ClearStatus () bool {
1601- InfoBar .Message ("" )
1602- return true
1631+ return h .ClearInfo ()
16031632}
16041633
16051634// ToggleHelp toggles the help screen
@@ -1654,12 +1683,18 @@ func (h *BufPane) Escape() bool {
16541683
16551684// Deselect deselects on the current cursor
16561685func (h * BufPane ) Deselect () bool {
1686+ if ! h .Cursor .HasSelection () {
1687+ return false
1688+ }
16571689 h .Cursor .Deselect (true )
16581690 return true
16591691}
16601692
16611693// ClearInfo clears the infobar
16621694func (h * BufPane ) ClearInfo () bool {
1695+ if InfoBar .Msg == "" {
1696+ return false
1697+ }
16631698 InfoBar .Message ("" )
16641699 return true
16651700}
@@ -1750,6 +1785,10 @@ func (h *BufPane) AddTab() bool {
17501785// PreviousTab switches to the previous tab in the tab list
17511786func (h * BufPane ) PreviousTab () bool {
17521787 tabsLen := len (Tabs .List )
1788+ if tabsLen == 1 {
1789+ return false
1790+ }
1791+
17531792 a := Tabs .Active () + tabsLen
17541793 Tabs .SetActive ((a - 1 ) % tabsLen )
17551794
@@ -1758,8 +1797,13 @@ func (h *BufPane) PreviousTab() bool {
17581797
17591798// NextTab switches to the next tab in the tab list
17601799func (h * BufPane ) NextTab () bool {
1800+ tabsLen := len (Tabs .List )
1801+ if tabsLen == 1 {
1802+ return false
1803+ }
1804+
17611805 a := Tabs .Active ()
1762- Tabs .SetActive ((a + 1 ) % len ( Tabs . List ) )
1806+ Tabs .SetActive ((a + 1 ) % tabsLen )
17631807
17641808 return true
17651809}
@@ -1795,6 +1839,10 @@ func (h *BufPane) Unsplit() bool {
17951839
17961840// NextSplit changes the view to the next split
17971841func (h * BufPane ) NextSplit () bool {
1842+ if len (h .tab .Panes ) == 1 {
1843+ return false
1844+ }
1845+
17981846 a := h .tab .active
17991847 if a < len (h .tab .Panes )- 1 {
18001848 a ++
@@ -1809,6 +1857,10 @@ func (h *BufPane) NextSplit() bool {
18091857
18101858// PreviousSplit changes the view to the previous split
18111859func (h * BufPane ) PreviousSplit () bool {
1860+ if len (h .tab .Panes ) == 1 {
1861+ return false
1862+ }
1863+
18121864 a := h .tab .active
18131865 if a > 0 {
18141866 a --
@@ -2010,6 +2062,9 @@ func (h *BufPane) MouseMultiCursor(e *tcell.EventMouse) bool {
20102062// SkipMultiCursor moves the current multiple cursor to the next available position
20112063func (h * BufPane ) SkipMultiCursor () bool {
20122064 lastC := h .Buf .GetCursor (h .Buf .NumCursors () - 1 )
2065+ if ! lastC .HasSelection () {
2066+ return false
2067+ }
20132068 sel := lastC .GetSelection ()
20142069 searchStart := lastC .CurSelection [1 ]
20152070
@@ -2045,17 +2100,24 @@ func (h *BufPane) RemoveMultiCursor() bool {
20452100 h .Buf .RemoveCursor (h .Buf .NumCursors () - 1 )
20462101 h .Buf .SetCurCursor (h .Buf .NumCursors () - 1 )
20472102 h .Buf .UpdateCursors ()
2048- } else {
2103+ } else if h . multiWord {
20492104 h .multiWord = false
2105+ h .Cursor .Deselect (true )
2106+ } else {
2107+ return false
20502108 }
20512109 h .Relocate ()
20522110 return true
20532111}
20542112
20552113// RemoveAllMultiCursors removes all cursors except the base cursor
20562114func (h * BufPane ) RemoveAllMultiCursors () bool {
2057- h .Buf .ClearCursors ()
2058- h .multiWord = false
2115+ if h .Buf .NumCursors () > 1 || h .multiWord {
2116+ h .Buf .ClearCursors ()
2117+ h .multiWord = false
2118+ } else {
2119+ return false
2120+ }
20592121 h .Relocate ()
20602122 return true
20612123}
0 commit comments