Implementation of Paragraph Feature

Changes to support moving cursor to next and previous paragraph
and updates to corresponding documentation
This commit is contained in:
Nitish Sakhawalkar
2017-10-02 19:01:01 -07:00
parent ac29e30f54
commit ec221c0bc4
4 changed files with 59 additions and 0 deletions

View File

@@ -493,6 +493,55 @@ func (v *View) SelectToEndOfLine(usePlugin bool) bool {
return true
}
// ParagraphPrevious moves the cursor to the previous empty line, or beginning of the buffer if there's none
func (v *View) ParagraphPrevious(usePlugin bool) bool {
if usePlugin && !PreActionCall("ParagraphPrevious", v) {
return false
}
var line int
for line = v.Cursor.Y; line > 0; line-- {
if len(v.Buf.lines[line].data) == 0 && line != v.Cursor.Y {
v.Cursor.X = 0
v.Cursor.Y = line
break
}
}
// If no empty line found. move cursor to end of buffer
if line == 0 {
v.Cursor.Loc = v.Buf.Start()
}
if usePlugin {
return PostActionCall("ParagraphPrevious", v)
}
return true
}
// ParagraphNext moves the cursor to the next empty line, or end of the buffer if there's none
func (v *View) ParagraphNext(usePlugin bool) bool {
if usePlugin && !PreActionCall("ParagraphNext", v) {
return false
}
var line int
for line = v.Cursor.Y; line < len(v.Buf.lines); line++ {
if len(v.Buf.lines[line].data) == 0 && line != v.Cursor.Y {
v.Cursor.X = 0
v.Cursor.Y = line
break
}
}
// If no empty line found. move cursor to end of buffer
if line == len(v.Buf.lines) {
v.Cursor.Loc = v.Buf.End()
}
if usePlugin {
return PostActionCall("ParagraphNext", v)
}
return true
}
// CursorStart moves the cursor to the start of the buffer
func (v *View) CursorStart(usePlugin bool) bool {
if usePlugin && !PreActionCall("CursorStart", v) {

View File

@@ -41,6 +41,8 @@ var bindingActions = map[string]func(*View, bool) bool{
"DeleteWordLeft": (*View).DeleteWordLeft,
"SelectToStartOfLine": (*View).SelectToStartOfLine,
"SelectToEndOfLine": (*View).SelectToEndOfLine,
"ParagraphPrevious": (*View).ParagraphPrevious,
"ParagraphNext": (*View).ParagraphNext,
"InsertNewline": (*View).InsertNewline,
"InsertSpace": (*View).InsertSpace,
"Backspace": (*View).Backspace,
@@ -458,6 +460,8 @@ func DefaultBindings() map[string]string {
"CtrlDown": "CursorEnd",
"CtrlShiftUp": "SelectToStart",
"CtrlShiftDown": "SelectToEnd",
"Alt-{": "ParagraphPrevious",
"Alt-}": "ParagraphNext",
"Enter": "InsertNewline",
"CtrlH": "Backspace",
"Backspace": "Backspace",

View File

@@ -25,6 +25,8 @@ If you don't like it, you can change it!
| End or CtrlRightArrow | Move to the end of the current line |
| AltLeftArrow | Move cursor one word left |
| AltRightArrow | Move cursor one word right |
| Alt+{ | Move cursor to previous empty line, or beginning of document |
| Alt+} | Move cursor to next empty line, or end of document |
| PageUp | Move cursor up one page |
| PageDown | Move cursor down one page |
| CtrlHome or CtrlUpArrow | Move cursor to start of document |

View File

@@ -113,6 +113,8 @@ HalfPageUp
HalfPageDown
StartOfLine
EndOfLine
ParagraphPrevious
ParagraphNext
ToggleHelp
ToggleRuler
JumpLine
@@ -315,6 +317,8 @@ MouseWheelRight
"CtrlDown": "CursorEnd",
"CtrlShiftUp": "SelectToStart",
"CtrlShiftDown": "SelectToEnd",
"Alt-{": "ParagraphPrevious",
"Alt-}": "ParagraphNext",
"Enter": "InsertNewline",
"CtrlH": "Backspace",
"Backspace": "Backspace",