diff --git a/gui/buffer.go b/gui/buffer.go index 2105d68..df026fa 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -926,7 +926,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) { highlightLinePosY := ey + (ry + b.curs.ry*last_h) - (b.cam.y * last_h) highlightLinePosX := ex + rx - ctx.Rect(highlightLinePosX, highlightLinePosY, b.w, last_h, strife.Fill) + ctx.Rect(highlightLinePosX, highlightLinePosY, b.w-ex, last_h, strife.Fill) } var visibleLines int = 50 diff --git a/gui/close_buffer.go b/gui/close_buffer.go index 77b32a8..c3787a8 100644 --- a/gui/close_buffer.go +++ b/gui/close_buffer.go @@ -1,5 +1,8 @@ package gui func CloseBuffer(b *Buffer) bool { + view := b.parent + view.ChangeFocus(-1) + view.removeBuffer(b.index) return false } diff --git a/gui/view.go b/gui/view.go index 6631427..089fd54 100644 --- a/gui/view.go +++ b/gui/view.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/felixangell/phi/cfg" "github.com/felixangell/strife" + "log" ) // View is an array of buffers basically. @@ -72,6 +73,24 @@ func sign(dir int) int { return 0 } +func (n *View) removeBuffer(index int) { + log.Println("Removing buffer index:", index) + delete(n.buffers, index) + + // only resize the buffers if we have + // some remaining in the window + if len(n.buffers) > 0 { + bufferWidth := n.w / len(n.buffers) + + // translate all the components accordingly. + for i, buff := range n.buffers { + buff.Resize(bufferWidth, n.h) + buff.SetPosition(bufferWidth*i, 0) + } + } + +} + func (n *View) ChangeFocus(dir int) { prevBuff, _ := n.buffers[n.focusedBuff] @@ -132,17 +151,13 @@ func (n *View) AddBuffer() *Buffer { // note that we +1 the components because // we haven't yet added the panel var bufferWidth int - bufferWidth = n.w / (len(n.buffers) + 1) + bufferWidth = n.w / (c.index + 1) n.buffers[c.index] = c n.focusedBuff = c.index // translate all the components accordingly. for i, buff := range n.buffers { - if buff == nil { - continue - } - buff.Resize(bufferWidth, n.h) buff.SetPosition(bufferWidth*i, 0) }