mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 14:27:12 +09:00
Fix statusline and tabbar offsets
This commit is contained in:
@@ -782,6 +782,7 @@ func (v *View) Quit() bool {
|
||||
}
|
||||
if curTab == 0 {
|
||||
// CurView().Resize(screen.Size())
|
||||
CurView().ToggleTabbar()
|
||||
CurView().matches = Match(CurView())
|
||||
}
|
||||
}
|
||||
@@ -799,13 +800,13 @@ func (v *View) AddTab() bool {
|
||||
tab.SetNum(len(tabs))
|
||||
tabs = append(tabs, tab)
|
||||
curTab++
|
||||
// if len(tabs) == 2 {
|
||||
// for _, t := range tabs {
|
||||
// for _, v := range t.views {
|
||||
// v.Resize(screen.Size())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if len(tabs) == 2 {
|
||||
for _, t := range tabs {
|
||||
for _, v := range t.views {
|
||||
v.ToggleTabbar()
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -126,13 +126,13 @@ func NewTab(args []string) {
|
||||
tab.SetNum(len(tabs))
|
||||
tabs = append(tabs, tab)
|
||||
curTab++
|
||||
// if len(tabs) == 2 {
|
||||
// for _, t := range tabs {
|
||||
// for _, v := range t.views {
|
||||
// v.Resize(screen.Size())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if len(tabs) == 2 {
|
||||
for _, t := range tabs {
|
||||
for _, v := range t.views {
|
||||
v.ToggleTabbar()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ func SetOption(view *View, args []string) {
|
||||
}
|
||||
|
||||
if option == "statusline" {
|
||||
// view.Resize(screen.Size())
|
||||
view.ToggleStatusLine()
|
||||
}
|
||||
|
||||
err := WriteSettings(filename)
|
||||
|
||||
@@ -142,6 +142,13 @@ func (s *SplitTree) ResizeSplits() {
|
||||
n.view.y = s.y + n.view.height*i
|
||||
n.view.x = s.x
|
||||
}
|
||||
// n.view.ToggleStatusLine()
|
||||
_, screenH := screen.Size()
|
||||
if settings["statusline"].(bool) || (n.view.y+n.view.height) != screenH-1 {
|
||||
n.view.height--
|
||||
}
|
||||
|
||||
n.view.ToggleTabbar()
|
||||
n.view.matches = Match(n.view)
|
||||
} else if n, ok := node.(*SplitTree); ok {
|
||||
if s.kind == VerticalSplit {
|
||||
|
||||
@@ -31,7 +31,7 @@ func NewTabFromView(v *View) *Tab {
|
||||
|
||||
w, h := screen.Size()
|
||||
t.tree.width = w
|
||||
t.tree.height = h
|
||||
t.tree.height = h - 1
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ func (t *Tab) Cleanup() {
|
||||
}
|
||||
|
||||
func (t *Tab) Resize() {
|
||||
w, h := screen.Size()
|
||||
t.tree.width = w
|
||||
t.tree.height = h - 1
|
||||
t.tree.ResizeSplits()
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,8 @@ func NewViewWidthHeight(buf *Buffer, w, h int) *View {
|
||||
v.width = w
|
||||
v.height = h
|
||||
|
||||
v.ToggleTabbar()
|
||||
|
||||
v.OpenBuffer(buf)
|
||||
|
||||
v.messages = make(map[string][]GutterMessage)
|
||||
@@ -117,6 +119,29 @@ func NewViewWidthHeight(buf *Buffer, w, h int) *View {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *View) ToggleStatusLine() {
|
||||
if settings["statusline"].(bool) {
|
||||
v.height--
|
||||
} else {
|
||||
v.height++
|
||||
}
|
||||
}
|
||||
|
||||
func (v *View) ToggleTabbar() {
|
||||
if len(tabs) > 1 {
|
||||
if v.y == 0 {
|
||||
// Include one line for the tab bar at the top
|
||||
v.height--
|
||||
v.y = 1
|
||||
}
|
||||
} else {
|
||||
if v.y == 1 {
|
||||
v.y = 0
|
||||
v.height++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ScrollUp scrolls the view up n lines (if possible)
|
||||
func (v *View) ScrollUp(n int) {
|
||||
// Try to scroll by n but if it would overflow, scroll by 1
|
||||
@@ -280,7 +305,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
switch e := event.(type) {
|
||||
case *tcell.EventResize:
|
||||
// Window resized
|
||||
// v.Resize(e.Size())
|
||||
tabs[v.TabNum].Resize()
|
||||
case *tcell.EventKey:
|
||||
if e.Key() == tcell.KeyRune && (e.Modifiers() == 0 || e.Modifiers() == tcell.ModShift) {
|
||||
// Insert a character
|
||||
|
||||
Reference in New Issue
Block a user