Skip to content

Commit 3aa5e19

Browse files
Merge branch 'ParagraphSelection' into dev
2 parents 9ec0662 + 1e6e946 commit 3aa5e19

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
> - [Changing syntax behavior for single quote to allow binary and hex literal separator #3310](https://github.com/zyedidia/micro/pull/3310)
88
> - [Fix indent selection #3102](https://github.com/zyedidia/micro/pull/3102)
99
> - [Add wrapindent option to allow wrapping and hanging indents #3107](https://github.com/zyedidia/micro/pull/3107)
10-
> - [Fixing tabmove not working properly when there's a split in pane #3371](https://github.com/zyedidia/micro/pull/3371)
1110
> - [add next/prev split/tab support for terminal pane #3165](https://github.com/zyedidia/micro/pull/3165)
1211
> - [Escape braces that are in string or comments when finding matching brace #3372](https://github.com/zyedidia/micro/pull/3372)
12+
> - [ Adding selection for ParagraphPrevious and ParagraphNext. #3353](https://github.com/zyedidia/micro/pull/3353)
1313
>
1414
> To see the diff between this and upstream master, click [here](https://github.com/zyedidia/micro/compare/master...Neko-Box-Coder:micro-dev:dev)
1515

internal/action/actions.go

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,38 +490,84 @@ func (h *BufPane) SelectToEndOfLine() bool {
490490
return true
491491
}
492492

493-
// ParagraphPrevious moves the cursor to the previous empty line, or beginning of the buffer if there's none
494-
func (h *BufPane) ParagraphPrevious() bool {
493+
func (h *BufPane) paragraphPrevious() {
495494
var line int
495+
// Skip to the first non-empty line
496496
for line = h.Cursor.Y; line > 0; line-- {
497+
if len(h.Buf.LineBytes(line)) != 0 {
498+
break
499+
}
500+
}
501+
// Find the first empty line
502+
for ; line > 0; line-- {
497503
if len(h.Buf.LineBytes(line)) == 0 && line != h.Cursor.Y {
498504
h.Cursor.X = 0
499505
h.Cursor.Y = line
500506
break
501507
}
502508
}
503-
// If no empty line found. move cursor to end of buffer
509+
// If no empty line was found, move the cursor to the start of the buffer
504510
if line == 0 {
505511
h.Cursor.Loc = h.Buf.Start()
506512
}
507-
h.Relocate()
508-
return true
509513
}
510514

511-
// ParagraphNext moves the cursor to the next empty line, or end of the buffer if there's none
512-
func (h *BufPane) ParagraphNext() bool {
515+
func (h *BufPane) paragraphNext() {
513516
var line int
517+
// Skip to the first non-empty line
514518
for line = h.Cursor.Y; line < h.Buf.LinesNum(); line++ {
519+
if len(h.Buf.LineBytes(line)) != 0 {
520+
break
521+
}
522+
}
523+
// Find the first empty line
524+
for ; line < h.Buf.LinesNum(); line++ {
515525
if len(h.Buf.LineBytes(line)) == 0 && line != h.Cursor.Y {
516526
h.Cursor.X = 0
517527
h.Cursor.Y = line
518528
break
519529
}
520530
}
521-
// If no empty line found. move cursor to end of buffer
531+
// If no empty line was found, move the cursor to the end of the buffer
522532
if line == h.Buf.LinesNum() {
523533
h.Cursor.Loc = h.Buf.End()
524534
}
535+
}
536+
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
538+
func (h *BufPane) ParagraphPrevious() bool {
539+
h.Cursor.Deselect(true)
540+
h.paragraphPrevious()
541+
h.Relocate()
542+
return true
543+
}
544+
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
546+
func (h *BufPane) ParagraphNext() bool {
547+
h.Cursor.Deselect(true)
548+
h.paragraphNext()
549+
h.Relocate()
550+
return true
551+
}
552+
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
554+
func (h *BufPane) SelectToParagraphPrevious() bool {
555+
if !h.Cursor.HasSelection() {
556+
h.Cursor.OrigSelection[0] = h.Cursor.Loc
557+
}
558+
h.paragraphPrevious()
559+
h.Cursor.SelectTo(h.Cursor.Loc)
560+
h.Relocate()
561+
return true
562+
}
563+
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
565+
func (h *BufPane) SelectToParagraphNext() bool {
566+
if !h.Cursor.HasSelection() {
567+
h.Cursor.OrigSelection[0] = h.Cursor.Loc
568+
}
569+
h.paragraphNext()
570+
h.Cursor.SelectTo(h.Cursor.Loc)
525571
h.Relocate()
526572
return true
527573
}

internal/action/bufpane.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ var BufKeyActions = map[string]BufKeyAction{
759759
"SelectToEndOfLine": (*BufPane).SelectToEndOfLine,
760760
"ParagraphPrevious": (*BufPane).ParagraphPrevious,
761761
"ParagraphNext": (*BufPane).ParagraphNext,
762+
"SelectToParagraphPrevious": (*BufPane).SelectToParagraphPrevious,
763+
"SelectToParagraphNext": (*BufPane).SelectToParagraphNext,
762764
"InsertNewline": (*BufPane).InsertNewline,
763765
"Backspace": (*BufPane).Backspace,
764766
"Delete": (*BufPane).Delete,

runtime/help/keybindings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ StartOfText
237237
StartOfTextToggle
238238
ParagraphPrevious
239239
ParagraphNext
240+
SelectToParagraphPrevious
241+
SelectToParagraphNext
240242
ToggleHelp
241243
ToggleDiffGutter
242244
ToggleRuler

0 commit comments

Comments
 (0)