"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"
)
BufKeyStrings[k] = action
BufKeyBindings[k] = f
} else {
- util.TermMessage("Error:", action, "does not exist")
+ screen.TermMessage("Error:", action, "does not exist")
}
}
// 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")
}
}
// 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
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
}
cursors := h.Buf.GetCursors()
for _, c := range cursors {
// Insert a character
+ h.Buf.SetCurCursor(c.Num)
if c.HasSelection() {
c.DeleteSelection()
c.ResetSelection()
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)})
}
}
}
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{