X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Faction%2Fbufhandler.go;h=ede74b5fd619bc6236b98e57e60f716898c1262e;hb=212b0f8c71edd37a8ca7ed76958b195c46186f84;hp=0ffa514fb906d315cc1531a42a6fbe195dca22a0;hpb=5701ed211add9e9409915e36a4b571e8fdef1dad;p=micro.git diff --git a/cmd/micro/action/bufhandler.go b/cmd/micro/action/bufhandler.go index 0ffa514f..ede74b5f 100644 --- a/cmd/micro/action/bufhandler.go +++ b/cmd/micro/action/bufhandler.go @@ -5,7 +5,7 @@ import ( "github.com/zyedidia/micro/cmd/micro/buffer" "github.com/zyedidia/micro/cmd/micro/display" - "github.com/zyedidia/micro/cmd/micro/util" + "github.com/zyedidia/micro/cmd/micro/screen" "github.com/zyedidia/tcell" ) @@ -28,7 +28,7 @@ func BufMapKey(k Event, action string) { BufKeyStrings[k] = action BufKeyBindings[k] = f } else { - util.TermMessage("Error:", action, "does not exist") + screen.TermMessage("Error:", action, "does not exist") } } @@ -43,7 +43,7 @@ func BufMapMouse(k MouseEvent, action string) { // ensure we don't double bind a key delete(BufMouseBindings, k) } else { - util.TermMessage("Error:", action, "does not exist") + screen.TermMessage("Error:", action, "does not exist") } } @@ -53,12 +53,11 @@ func BufMapMouse(k MouseEvent, action string) { // The ActionHandler can access the window for necessary info about // visual positions for mouse clicks and scrolling type BufHandler struct { - display.Window + display.BWindow Buf *buffer.Buffer - cursors []*buffer.Cursor - Cursor *buffer.Cursor // the active cursor + Cursor *buffer.Cursor // the active cursor StartLine int // Vertical scrolling StartCol int // Horizontal scrolling @@ -99,19 +98,34 @@ type BufHandler struct { splitID uint64 } -func NewBufHandler(buf *buffer.Buffer, win display.Window) *BufHandler { +func NewBufHandler(buf *buffer.Buffer, win display.BWindow) *BufHandler { h := new(BufHandler) h.Buf = buf - h.Window = win + h.BWindow = win - h.cursors = []*buffer.Cursor{buffer.NewCursor(buf, buf.StartCursor)} - h.Cursor = h.cursors[0] + h.Cursor = h.Buf.GetActiveCursor() h.mouseReleased = true - buf.SetCursors(h.cursors) return h } +func (h *BufHandler) OpenBuffer(b *buffer.Buffer) { + h.Buf.Close() + h.Buf = b + h.BWindow.SetBuffer(b) + h.Cursor = b.GetActiveCursor() + 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 + h.mouseReleased = true + // Set isOverwriteMode to false, because we assume we are in the default mode when editor + // is opened + h.isOverwriteMode = false + h.lastClickTime = time.Time{} +} + func (h *BufHandler) ID() uint64 { return h.splitID } @@ -239,6 +253,7 @@ func (h *BufHandler) DoRuneInsert(r rune) { cursors := h.Buf.GetCursors() for _, c := range cursors { // Insert a character + h.Buf.SetCurCursor(c.Num) if c.HasSelection() { c.DeleteSelection() c.ResetSelection() @@ -247,9 +262,9 @@ func (h *BufHandler) DoRuneInsert(r rune) { if h.isOverwriteMode { next := c.Loc next.X++ - h.Buf.Replace(c.Loc, next, string(r)) + h.Buf.Replace(c.Loc, next, []byte{byte(r)}) } else { - h.Buf.Insert(c.Loc, string(r)) + h.Buf.Insert(c.Loc, []byte{byte(r)}) } } } @@ -268,6 +283,9 @@ func (h *BufHandler) HSplitBuf(buf *buffer.Buffer) { MainTab().Resize() MainTab().SetActive(len(MainTab().Panes) - 1) } +func (h *BufHandler) Close() { + h.Buf.Close() +} // BufKeyActions contains the list of all possible key actions the bufhandler could execute var BufKeyActions = map[string]BufKeyAction{