Add OpenBuffer() function to View

Fixes #43
This commit is contained in:
Zachary Yedidia
2016-04-19 18:58:52 -04:00
parent aaa0f29540
commit c767b3dc0c
2 changed files with 26 additions and 3 deletions

View File

@@ -276,6 +276,29 @@ func (v *View) SelectAll() {
v.cursor.y = 0
}
// OpenBuffer opens a new buffer in this view.
// This resets the topline, event handler and cursor.
func (v *View) OpenBuffer(buf *Buffer) {
v.buf = buf
v.topline = 0
// Put the cursor at the first spot
v.cursor = Cursor{
x: 0,
y: 0,
v: v,
}
v.cursor.ResetSelection()
v.eh = NewEventHandler(v)
v.matches = Match(v)
// Set mouseReleased to true because we assume the mouse is not being pressed when
// the editor is opened
v.mouseReleased = true
v.lastClickTime = time.Time{}
}
// OpenFile opens a new file in the current view
// It makes sure that the current buffer can be closed first (unsaved changes)
func (v *View) OpenFile() {