mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Add JumpToMatchingBrace action
This commit adds the JumpToMatchingBrace action which lets the cursor jump to a matching brace if it is on one. Closes #853
This commit is contained in:
@@ -1357,6 +1357,27 @@ func (v *View) PastePrimary(usePlugin bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// JumpToMatchingBrace moves the cursor to the matching brace if it is
|
||||
// currently on a brace
|
||||
func (v *View) JumpToMatchingBrace(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("JumpToMatchingBrace", v) {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, bp := range bracePairs {
|
||||
r := v.Cursor.RuneUnder(v.Cursor.X)
|
||||
if r == bp[0] || r == bp[1] {
|
||||
matchingBrace := v.Buf.FindMatchingBrace(bp, v.Cursor.Loc)
|
||||
v.Cursor.GotoLoc(matchingBrace)
|
||||
}
|
||||
}
|
||||
|
||||
if usePlugin {
|
||||
return PostActionCall("JumpToMatchingBrace", v)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// SelectAll selects the entire buffer
|
||||
func (v *View) SelectAll(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("SelectAll", v) {
|
||||
|
||||
@@ -111,6 +111,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
||||
"RemoveMultiCursor": (*View).RemoveMultiCursor,
|
||||
"RemoveAllMultiCursors": (*View).RemoveAllMultiCursors,
|
||||
"SkipMultiCursor": (*View).SkipMultiCursor,
|
||||
"JumpToMatchingBrace": (*View).JumpToMatchingBrace,
|
||||
|
||||
// This was changed to InsertNewline but I don't want to break backwards compatibility
|
||||
"InsertEnter": (*View).InsertNewline,
|
||||
|
||||
@@ -150,7 +150,6 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
|
||||
if viewCol >= 0 {
|
||||
st := curStyle
|
||||
if colN == matchingBrace.X && lineN == matchingBrace.Y {
|
||||
messenger.Message(matchingBrace)
|
||||
st = curStyle.Reverse(true)
|
||||
}
|
||||
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, st, 1}
|
||||
|
||||
@@ -35,6 +35,13 @@ func (c *Cursor) Goto(b Cursor) {
|
||||
c.OrigSelection, c.CurSelection = b.OrigSelection, b.CurSelection
|
||||
}
|
||||
|
||||
// GotoLoc puts the cursor at the given cursor's location and gives
|
||||
// the current cursor its selection too
|
||||
func (c *Cursor) GotoLoc(l Loc) {
|
||||
c.X, c.Y = l.X, l.Y
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
}
|
||||
|
||||
// CopySelection copies the user's selection to either "primary"
|
||||
// or "clipboard"
|
||||
func (c *Cursor) CopySelection(target string) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -218,6 +218,7 @@ RemoveMultiCursor
|
||||
RemoveAllMultiCursors
|
||||
SkipMultiCursor
|
||||
UnbindKey
|
||||
JumpToMatchingBrace
|
||||
```
|
||||
|
||||
You can also bind some mouse actions (these must be bound to mouse buttons)
|
||||
|
||||
@@ -182,6 +182,10 @@ Here are the options that you can set:
|
||||
|
||||
default value: `on`
|
||||
|
||||
* `matchbrace`: highlight matching braces for '()', '{}', '[]'
|
||||
|
||||
default value: `off`
|
||||
|
||||
* `syntax`: turns syntax on or off.
|
||||
|
||||
default value: `on`
|
||||
|
||||
Reference in New Issue
Block a user