mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-15 13:27:13 +09:00
Merge pull request #3352 from dmaluka/action-return-values
Improve return values of some actions + some improvements
This commit is contained in:
@@ -1122,6 +1122,9 @@ func (h *BufPane) ToggleHighlightSearch() bool {
|
|||||||
|
|
||||||
// UnhighlightSearch unhighlights all instances of the last used search term
|
// UnhighlightSearch unhighlights all instances of the last used search term
|
||||||
func (h *BufPane) UnhighlightSearch() bool {
|
func (h *BufPane) UnhighlightSearch() bool {
|
||||||
|
if !h.Buf.HighlightSearch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
h.Buf.HighlightSearch = false
|
h.Buf.HighlightSearch = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1217,7 +1220,9 @@ func (h *BufPane) DiffPrevious() bool {
|
|||||||
|
|
||||||
// Undo undoes the last action
|
// Undo undoes the last action
|
||||||
func (h *BufPane) Undo() bool {
|
func (h *BufPane) Undo() bool {
|
||||||
h.Buf.Undo()
|
if !h.Buf.Undo() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
InfoBar.Message("Undid action")
|
InfoBar.Message("Undid action")
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
@@ -1225,7 +1230,9 @@ func (h *BufPane) Undo() bool {
|
|||||||
|
|
||||||
// Redo redoes the last action
|
// Redo redoes the last action
|
||||||
func (h *BufPane) Redo() bool {
|
func (h *BufPane) Redo() bool {
|
||||||
h.Buf.Redo()
|
if !h.Buf.Redo() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
InfoBar.Message("Redid action")
|
InfoBar.Message("Redid action")
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
@@ -1624,10 +1631,9 @@ func (h *BufPane) ToggleRuler() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearStatus clears the messenger bar
|
// ClearStatus clears the infobar. It is an alias for ClearInfo.
|
||||||
func (h *BufPane) ClearStatus() bool {
|
func (h *BufPane) ClearStatus() bool {
|
||||||
InfoBar.Message("")
|
return h.ClearInfo()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToggleHelp toggles the help screen
|
// ToggleHelp toggles the help screen
|
||||||
@@ -1682,12 +1688,18 @@ func (h *BufPane) Escape() bool {
|
|||||||
|
|
||||||
// Deselect deselects on the current cursor
|
// Deselect deselects on the current cursor
|
||||||
func (h *BufPane) Deselect() bool {
|
func (h *BufPane) Deselect() bool {
|
||||||
|
if !h.Cursor.HasSelection() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
h.Cursor.Deselect(true)
|
h.Cursor.Deselect(true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearInfo clears the infobar
|
// ClearInfo clears the infobar
|
||||||
func (h *BufPane) ClearInfo() bool {
|
func (h *BufPane) ClearInfo() bool {
|
||||||
|
if InfoBar.Msg == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
InfoBar.Message("")
|
InfoBar.Message("")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1778,6 +1790,10 @@ func (h *BufPane) AddTab() bool {
|
|||||||
// PreviousTab switches to the previous tab in the tab list
|
// PreviousTab switches to the previous tab in the tab list
|
||||||
func (h *BufPane) PreviousTab() bool {
|
func (h *BufPane) PreviousTab() bool {
|
||||||
tabsLen := len(Tabs.List)
|
tabsLen := len(Tabs.List)
|
||||||
|
if tabsLen == 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
a := Tabs.Active() + tabsLen
|
a := Tabs.Active() + tabsLen
|
||||||
Tabs.SetActive((a - 1) % tabsLen)
|
Tabs.SetActive((a - 1) % tabsLen)
|
||||||
|
|
||||||
@@ -1786,8 +1802,13 @@ func (h *BufPane) PreviousTab() bool {
|
|||||||
|
|
||||||
// NextTab switches to the next tab in the tab list
|
// NextTab switches to the next tab in the tab list
|
||||||
func (h *BufPane) NextTab() bool {
|
func (h *BufPane) NextTab() bool {
|
||||||
|
tabsLen := len(Tabs.List)
|
||||||
|
if tabsLen == 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
a := Tabs.Active()
|
a := Tabs.Active()
|
||||||
Tabs.SetActive((a + 1) % len(Tabs.List))
|
Tabs.SetActive((a + 1) % tabsLen)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1823,6 +1844,10 @@ func (h *BufPane) Unsplit() bool {
|
|||||||
|
|
||||||
// NextSplit changes the view to the next split
|
// NextSplit changes the view to the next split
|
||||||
func (h *BufPane) NextSplit() bool {
|
func (h *BufPane) NextSplit() bool {
|
||||||
|
if len(h.tab.Panes) == 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
a := h.tab.active
|
a := h.tab.active
|
||||||
if a < len(h.tab.Panes)-1 {
|
if a < len(h.tab.Panes)-1 {
|
||||||
a++
|
a++
|
||||||
@@ -1837,6 +1862,10 @@ func (h *BufPane) NextSplit() bool {
|
|||||||
|
|
||||||
// PreviousSplit changes the view to the previous split
|
// PreviousSplit changes the view to the previous split
|
||||||
func (h *BufPane) PreviousSplit() bool {
|
func (h *BufPane) PreviousSplit() bool {
|
||||||
|
if len(h.tab.Panes) == 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
a := h.tab.active
|
a := h.tab.active
|
||||||
if a > 0 {
|
if a > 0 {
|
||||||
a--
|
a--
|
||||||
@@ -2038,6 +2067,9 @@ func (h *BufPane) MouseMultiCursor(e *tcell.EventMouse) bool {
|
|||||||
// SkipMultiCursor moves the current multiple cursor to the next available position
|
// SkipMultiCursor moves the current multiple cursor to the next available position
|
||||||
func (h *BufPane) SkipMultiCursor() bool {
|
func (h *BufPane) SkipMultiCursor() bool {
|
||||||
lastC := h.Buf.GetCursor(h.Buf.NumCursors() - 1)
|
lastC := h.Buf.GetCursor(h.Buf.NumCursors() - 1)
|
||||||
|
if !lastC.HasSelection() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
sel := lastC.GetSelection()
|
sel := lastC.GetSelection()
|
||||||
searchStart := lastC.CurSelection[1]
|
searchStart := lastC.CurSelection[1]
|
||||||
|
|
||||||
@@ -2073,8 +2105,11 @@ func (h *BufPane) RemoveMultiCursor() bool {
|
|||||||
h.Buf.RemoveCursor(h.Buf.NumCursors() - 1)
|
h.Buf.RemoveCursor(h.Buf.NumCursors() - 1)
|
||||||
h.Buf.SetCurCursor(h.Buf.NumCursors() - 1)
|
h.Buf.SetCurCursor(h.Buf.NumCursors() - 1)
|
||||||
h.Buf.UpdateCursors()
|
h.Buf.UpdateCursors()
|
||||||
} else {
|
} else if h.multiWord {
|
||||||
h.multiWord = false
|
h.multiWord = false
|
||||||
|
h.Cursor.Deselect(true)
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
@@ -2082,8 +2117,12 @@ func (h *BufPane) RemoveMultiCursor() bool {
|
|||||||
|
|
||||||
// RemoveAllMultiCursors removes all cursors except the base cursor
|
// RemoveAllMultiCursors removes all cursors except the base cursor
|
||||||
func (h *BufPane) RemoveAllMultiCursors() bool {
|
func (h *BufPane) RemoveAllMultiCursors() bool {
|
||||||
h.Buf.ClearCursors()
|
if h.Buf.NumCursors() > 1 || h.multiWord {
|
||||||
h.multiWord = false
|
h.Buf.ClearCursors()
|
||||||
|
h.multiWord = false
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,29 +150,31 @@ func BufMapEvent(k Event, action string) {
|
|||||||
actionfns = append(actionfns, afn)
|
actionfns = append(actionfns, afn)
|
||||||
}
|
}
|
||||||
bufAction := func(h *BufPane, te *tcell.EventMouse) bool {
|
bufAction := func(h *BufPane, te *tcell.EventMouse) bool {
|
||||||
cursors := h.Buf.GetCursors()
|
|
||||||
success := true
|
|
||||||
for i, a := range actionfns {
|
for i, a := range actionfns {
|
||||||
innerSuccess := true
|
var success bool
|
||||||
for j, c := range cursors {
|
if _, ok := MultiActions[names[i]]; ok {
|
||||||
if c == nil {
|
success = true
|
||||||
continue
|
for _, c := range h.Buf.GetCursors() {
|
||||||
}
|
h.Buf.SetCurCursor(c.Num)
|
||||||
h.Buf.SetCurCursor(c.Num)
|
h.Cursor = c
|
||||||
h.Cursor = c
|
success = success && h.execAction(a, names[i], te)
|
||||||
if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') {
|
|
||||||
innerSuccess = innerSuccess && h.execAction(a, names[i], j, te)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
h.Buf.SetCurCursor(0)
|
||||||
|
h.Cursor = h.Buf.GetActiveCursor()
|
||||||
|
success = h.execAction(a, names[i], te)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the action changed the current pane, update the reference
|
// if the action changed the current pane, update the reference
|
||||||
h = MainTab().CurPane()
|
h = MainTab().CurPane()
|
||||||
success = innerSuccess
|
|
||||||
if h == nil {
|
if h == nil {
|
||||||
// stop, in case the current pane is not a BufPane
|
// stop, in case the current pane is not a BufPane
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!success && types[i] == '&') || (success && types[i] == '|') {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -562,36 +564,33 @@ func (h *BufPane) DoKeyEvent(e Event) bool {
|
|||||||
return more
|
return more
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *BufPane) execAction(action BufAction, name string, cursor int, te *tcell.EventMouse) bool {
|
func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse) bool {
|
||||||
if name != "Autocomplete" && name != "CycleAutocompleteBack" {
|
if name != "Autocomplete" && name != "CycleAutocompleteBack" {
|
||||||
h.Buf.HasSuggestions = false
|
h.Buf.HasSuggestions = false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, isMulti := MultiActions[name]
|
if !h.PluginCB("pre" + name) {
|
||||||
if (!isMulti && cursor == 0) || isMulti {
|
return false
|
||||||
if h.PluginCB("pre" + name) {
|
}
|
||||||
var success bool
|
|
||||||
switch a := action.(type) {
|
|
||||||
case BufKeyAction:
|
|
||||||
success = a(h)
|
|
||||||
case BufMouseAction:
|
|
||||||
success = a(h, te)
|
|
||||||
}
|
|
||||||
success = success && h.PluginCB("on"+name)
|
|
||||||
|
|
||||||
if isMulti {
|
var success bool
|
||||||
if recordingMacro {
|
switch a := action.(type) {
|
||||||
if name != "ToggleMacro" && name != "PlayMacro" {
|
case BufKeyAction:
|
||||||
curmacro = append(curmacro, action)
|
success = a(h)
|
||||||
}
|
case BufMouseAction:
|
||||||
}
|
success = a(h, te)
|
||||||
}
|
}
|
||||||
|
success = success && h.PluginCB("on"+name)
|
||||||
|
|
||||||
return success
|
if _, ok := MultiActions[name]; ok {
|
||||||
|
if recordingMacro {
|
||||||
|
if name != "ToggleMacro" && name != "PlayMacro" {
|
||||||
|
curmacro = append(curmacro, action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *BufPane) completeAction(action string) {
|
func (h *BufPane) completeAction(action string) {
|
||||||
|
|||||||
@@ -1089,7 +1089,7 @@ func (b *Buffer) ClearCursors() {
|
|||||||
b.cursors = b.cursors[:1]
|
b.cursors = b.cursors[:1]
|
||||||
b.UpdateCursors()
|
b.UpdateCursors()
|
||||||
b.curCursor = 0
|
b.curCursor = 0
|
||||||
b.GetActiveCursor().ResetSelection()
|
b.GetActiveCursor().Deselect(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveLinesUp moves the range of lines up one row
|
// MoveLinesUp moves the range of lines up one row
|
||||||
|
|||||||
@@ -253,11 +253,11 @@ func (eh *EventHandler) Execute(t *TextEvent) {
|
|||||||
ExecuteTextEvent(t, eh.buf)
|
ExecuteTextEvent(t, eh.buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undo the first event in the undo stack
|
// Undo the first event in the undo stack. Returns false if the stack is empty.
|
||||||
func (eh *EventHandler) Undo() {
|
func (eh *EventHandler) Undo() bool {
|
||||||
t := eh.UndoStack.Peek()
|
t := eh.UndoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||||
@@ -266,15 +266,16 @@ func (eh *EventHandler) Undo() {
|
|||||||
for {
|
for {
|
||||||
t = eh.UndoStack.Peek()
|
t = eh.UndoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Time.UnixNano()/int64(time.Millisecond) < endTime {
|
if t.Time.UnixNano()/int64(time.Millisecond) < endTime {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
eh.UndoOneEvent()
|
eh.UndoOneEvent()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// UndoOneEvent undoes one event
|
// UndoOneEvent undoes one event
|
||||||
@@ -303,11 +304,11 @@ func (eh *EventHandler) UndoOneEvent() {
|
|||||||
eh.RedoStack.Push(t)
|
eh.RedoStack.Push(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redo the first event in the redo stack
|
// Redo the first event in the redo stack. Returns false if the stack is empty.
|
||||||
func (eh *EventHandler) Redo() {
|
func (eh *EventHandler) Redo() bool {
|
||||||
t := eh.RedoStack.Peek()
|
t := eh.RedoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||||
@@ -316,15 +317,16 @@ func (eh *EventHandler) Redo() {
|
|||||||
for {
|
for {
|
||||||
t = eh.RedoStack.Peek()
|
t = eh.RedoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Time.UnixNano()/int64(time.Millisecond) > endTime {
|
if t.Time.UnixNano()/int64(time.Millisecond) > endTime {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
eh.RedoOneEvent()
|
eh.RedoOneEvent()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// RedoOneEvent redoes one event
|
// RedoOneEvent redoes one event
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ ToggleDiffGutter
|
|||||||
ToggleRuler
|
ToggleRuler
|
||||||
JumpLine
|
JumpLine
|
||||||
ResetSearch
|
ResetSearch
|
||||||
|
ClearInfo
|
||||||
ClearStatus
|
ClearStatus
|
||||||
ShellMode
|
ShellMode
|
||||||
CommandMode
|
CommandMode
|
||||||
|
|||||||
Reference in New Issue
Block a user