mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 14:22:42 +09:00
Implementation of Paragraph Feature
Changes to support moving cursor to next and previous paragraph and updates to corresponding documentation
This commit is contained in:
@@ -493,6 +493,55 @@ func (v *View) SelectToEndOfLine(usePlugin bool) bool {
|
|||||||
return true
|
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
|
// CursorStart moves the cursor to the start of the buffer
|
||||||
func (v *View) CursorStart(usePlugin bool) bool {
|
func (v *View) CursorStart(usePlugin bool) bool {
|
||||||
if usePlugin && !PreActionCall("CursorStart", v) {
|
if usePlugin && !PreActionCall("CursorStart", v) {
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ var bindingActions = map[string]func(*View, bool) bool{
|
|||||||
"DeleteWordLeft": (*View).DeleteWordLeft,
|
"DeleteWordLeft": (*View).DeleteWordLeft,
|
||||||
"SelectToStartOfLine": (*View).SelectToStartOfLine,
|
"SelectToStartOfLine": (*View).SelectToStartOfLine,
|
||||||
"SelectToEndOfLine": (*View).SelectToEndOfLine,
|
"SelectToEndOfLine": (*View).SelectToEndOfLine,
|
||||||
|
"ParagraphPrevious": (*View).ParagraphPrevious,
|
||||||
|
"ParagraphNext": (*View).ParagraphNext,
|
||||||
"InsertNewline": (*View).InsertNewline,
|
"InsertNewline": (*View).InsertNewline,
|
||||||
"InsertSpace": (*View).InsertSpace,
|
"InsertSpace": (*View).InsertSpace,
|
||||||
"Backspace": (*View).Backspace,
|
"Backspace": (*View).Backspace,
|
||||||
@@ -458,6 +460,8 @@ func DefaultBindings() map[string]string {
|
|||||||
"CtrlDown": "CursorEnd",
|
"CtrlDown": "CursorEnd",
|
||||||
"CtrlShiftUp": "SelectToStart",
|
"CtrlShiftUp": "SelectToStart",
|
||||||
"CtrlShiftDown": "SelectToEnd",
|
"CtrlShiftDown": "SelectToEnd",
|
||||||
|
"Alt-{": "ParagraphPrevious",
|
||||||
|
"Alt-}": "ParagraphNext",
|
||||||
"Enter": "InsertNewline",
|
"Enter": "InsertNewline",
|
||||||
"CtrlH": "Backspace",
|
"CtrlH": "Backspace",
|
||||||
"Backspace": "Backspace",
|
"Backspace": "Backspace",
|
||||||
|
|||||||
@@ -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 |
|
| End or CtrlRightArrow | Move to the end of the current line |
|
||||||
| AltLeftArrow | Move cursor one word left |
|
| AltLeftArrow | Move cursor one word left |
|
||||||
| AltRightArrow | Move cursor one word right |
|
| 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 |
|
| PageUp | Move cursor up one page |
|
||||||
| PageDown | Move cursor down one page |
|
| PageDown | Move cursor down one page |
|
||||||
| CtrlHome or CtrlUpArrow | Move cursor to start of document |
|
| CtrlHome or CtrlUpArrow | Move cursor to start of document |
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ HalfPageUp
|
|||||||
HalfPageDown
|
HalfPageDown
|
||||||
StartOfLine
|
StartOfLine
|
||||||
EndOfLine
|
EndOfLine
|
||||||
|
ParagraphPrevious
|
||||||
|
ParagraphNext
|
||||||
ToggleHelp
|
ToggleHelp
|
||||||
ToggleRuler
|
ToggleRuler
|
||||||
JumpLine
|
JumpLine
|
||||||
@@ -315,6 +317,8 @@ MouseWheelRight
|
|||||||
"CtrlDown": "CursorEnd",
|
"CtrlDown": "CursorEnd",
|
||||||
"CtrlShiftUp": "SelectToStart",
|
"CtrlShiftUp": "SelectToStart",
|
||||||
"CtrlShiftDown": "SelectToEnd",
|
"CtrlShiftDown": "SelectToEnd",
|
||||||
|
"Alt-{": "ParagraphPrevious",
|
||||||
|
"Alt-}": "ParagraphNext",
|
||||||
"Enter": "InsertNewline",
|
"Enter": "InsertNewline",
|
||||||
"CtrlH": "Backspace",
|
"CtrlH": "Backspace",
|
||||||
"Backspace": "Backspace",
|
"Backspace": "Backspace",
|
||||||
|
|||||||
Reference in New Issue
Block a user