X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=internal%2Faction%2Fbufpane.go;h=d63f0a2056a8a6c06c303121cc1dfc35a27adcb0;hb=e1827480c94a2c5ddd101a0cabf82ebea1ee8d33;hp=71246b24d1bf82218d69d6562c626d6aac4b9fb1;hpb=97665573c7f7eaccf76d1150578a0c255fb0f810;p=micro.git diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 71246b24..d63f0a20 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -91,7 +91,14 @@ func BufMapKey(k Event, action string) { screen.TermMessage("Lua Error:", a, "does not exist") continue } - names = append(names, "") + split := strings.SplitN(a, ".", 2) + if len(split) > 1 { + a = strings.Title(split[0]) + strings.Title(split[1]) + } else { + a = strings.Title(a) + } + + names = append(names, a) } else if f, ok := BufKeyActions[a]; ok { afn = f names = append(names, a) @@ -106,6 +113,9 @@ func BufMapKey(k Event, action string) { success := true for i, a := range actionfns { for j, c := range cursors { + if c == nil { + continue + } h.Buf.SetCurCursor(c.Num) h.Cursor = c if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') { @@ -175,15 +185,17 @@ type BufPane struct { multiWord bool splitID uint64 + tab *Tab // remember original location of a search in case the search is canceled searchOrig buffer.Loc } -func NewBufPane(buf *buffer.Buffer, win display.BWindow) *BufPane { +func NewBufPane(buf *buffer.Buffer, win display.BWindow, tab *Tab) *BufPane { h := new(BufPane) h.Buf = buf h.BWindow = win + h.tab = tab h.Cursor = h.Buf.GetActiveCursor() h.mouseReleased = true @@ -193,9 +205,23 @@ func NewBufPane(buf *buffer.Buffer, win display.BWindow) *BufPane { return h } -func NewBufPaneFromBuf(buf *buffer.Buffer) *BufPane { +func NewBufPaneFromBuf(buf *buffer.Buffer, tab *Tab) *BufPane { w := display.NewBufWindow(0, 0, 0, 0, buf) - return NewBufPane(buf, w) + return NewBufPane(buf, w, tab) +} + +func (h *BufPane) SetTab(t *Tab) { + h.tab = t +} + +func (h *BufPane) Tab() *Tab { + return h.tab +} + +func (h *BufPane) ResizePane(size int) { + n := h.tab.GetNode(h.splitID) + n.ResizeSplit(size) + h.tab.Resize() } // PluginCB calls all plugin callbacks with a certain name and @@ -225,8 +251,6 @@ func (h *BufPane) OpenBuffer(b *buffer.Buffer) { h.BWindow.SetBuffer(b) h.Cursor = b.GetActiveCursor() h.Resize(h.GetView().Width, h.GetView().Height) - v := new(display.View) - h.SetView(v) h.Relocate() // Set mouseReleased to true because we assume the mouse is not being pressed when // the editor is opened @@ -251,8 +275,11 @@ func (h *BufPane) Name() string { // HandleEvent executes the tcell event properly func (h *BufPane) HandleEvent(event tcell.Event) { - if h.Buf.ExternallyModified() { - InfoBar.YNPrompt("The file on disk has changed. Reload file? (y,n)", func(yes, canceled bool) { + if h.Buf.ExternallyModified() && !h.Buf.ReloadDisabled { + InfoBar.YNPrompt("The file on disk has changed. Reload file? (y,n,esc)", func(yes, canceled bool) { + if canceled { + h.Buf.DisableReload() + } if !yes || canceled { h.Buf.UpdateModTime() } else { @@ -357,7 +384,7 @@ func (h *BufPane) DoKeyEvent(e Event) bool { } func (h *BufPane) execAction(action func(*BufPane) bool, name string, cursor int) bool { - if name != "Autocomplete" { + if name != "Autocomplete" && name != "CycleAutocompleteBack" { h.Buf.HasSuggestions = false } @@ -431,26 +458,34 @@ func (h *BufPane) DoRuneInsert(r rune) { if recording_macro { curmacro = append(curmacro, r) } + h.Relocate() h.PluginCBRune("onRune", r) } } -func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane { - e := NewBufPaneFromBuf(buf) - e.splitID = MainTab().GetNode(h.splitID).VSplit(h.Buf.Settings["splitright"].(bool)) +func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane { + e := NewBufPaneFromBuf(buf, h.tab) + e.splitID = MainTab().GetNode(h.splitID).VSplit(right) MainTab().Panes = append(MainTab().Panes, e) MainTab().Resize() MainTab().SetActive(len(MainTab().Panes) - 1) return e } -func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane { - e := NewBufPaneFromBuf(buf) - e.splitID = MainTab().GetNode(h.splitID).HSplit(h.Buf.Settings["splitbottom"].(bool)) +func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane { + e := NewBufPaneFromBuf(buf, h.tab) + e.splitID = MainTab().GetNode(h.splitID).HSplit(bottom) MainTab().Panes = append(MainTab().Panes, e) MainTab().Resize() MainTab().SetActive(len(MainTab().Panes) - 1) return e } + +func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane { + return h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool)) +} +func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane { + return h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool)) +} func (h *BufPane) Close() { h.Buf.Close() } @@ -499,6 +534,7 @@ var BufKeyActions = map[string]BufKeyAction{ "DeleteWordLeft": (*BufPane).DeleteWordLeft, "SelectLine": (*BufPane).SelectLine, "SelectToStartOfLine": (*BufPane).SelectToStartOfLine, + "SelectToStartOfText": (*BufPane).SelectToStartOfText, "SelectToEndOfLine": (*BufPane).SelectToEndOfLine, "ParagraphPrevious": (*BufPane).ParagraphPrevious, "ParagraphNext": (*BufPane).ParagraphNext, @@ -525,7 +561,9 @@ var BufKeyActions = map[string]BufKeyAction{ "IndentSelection": (*BufPane).IndentSelection, "OutdentSelection": (*BufPane).OutdentSelection, "Autocomplete": (*BufPane).Autocomplete, + "CycleAutocompleteBack": (*BufPane).CycleAutocompleteBack, "OutdentLine": (*BufPane).OutdentLine, + "IndentLine": (*BufPane).IndentLine, "Paste": (*BufPane).Paste, "PastePrimary": (*BufPane).PastePrimary, "SelectAll": (*BufPane).SelectAll, @@ -538,10 +576,12 @@ var BufKeyActions = map[string]BufKeyAction{ "SelectPageDown": (*BufPane).SelectPageDown, "HalfPageUp": (*BufPane).HalfPageUp, "HalfPageDown": (*BufPane).HalfPageDown, + "StartOfText": (*BufPane).StartOfText, "StartOfLine": (*BufPane).StartOfLine, "EndOfLine": (*BufPane).EndOfLine, "ToggleHelp": (*BufPane).ToggleHelp, "ToggleKeyMenu": (*BufPane).ToggleKeyMenu, + "ToggleDiffGutter": (*BufPane).ToggleDiffGutter, "ToggleRuler": (*BufPane).ToggleRuler, "ClearStatus": (*BufPane).ClearStatus, "ShellMode": (*BufPane).ShellMode, @@ -564,6 +604,8 @@ var BufKeyActions = map[string]BufKeyAction{ "ScrollUp": (*BufPane).ScrollUpAction, "ScrollDown": (*BufPane).ScrollDownAction, "SpawnMultiCursor": (*BufPane).SpawnMultiCursor, + "SpawnMultiCursorUp": (*BufPane).SpawnMultiCursorUp, + "SpawnMultiCursorDown": (*BufPane).SpawnMultiCursorDown, "SpawnMultiCursorSelect": (*BufPane).SpawnMultiCursorSelect, "RemoveMultiCursor": (*BufPane).RemoveMultiCursor, "RemoveAllMultiCursors": (*BufPane).RemoveAllMultiCursors, @@ -608,6 +650,7 @@ var MultiActions = map[string]bool{ "DeleteWordLeft": true, "SelectLine": true, "SelectToStartOfLine": true, + "SelectToStartOfText": true, "SelectToEndOfLine": true, "ParagraphPrevious": true, "ParagraphNext": true, @@ -626,11 +669,13 @@ var MultiActions = map[string]bool{ "IndentSelection": true, "OutdentSelection": true, "OutdentLine": true, + "IndentLine": true, "Paste": true, "PastePrimary": true, "SelectPageUp": true, "SelectPageDown": true, "StartOfLine": true, + "StartOfText": true, "EndOfLine": true, "JumpToMatchingBrace": true, }