fix(split-editors): resize issue

This commit is contained in:
Maas Lalani 2022-08-18 15:49:36 -04:00
parent 4e9a56f70d
commit a7f50a670c
1 changed files with 5 additions and 2 deletions

View File

@ -15,6 +15,7 @@ const (
initialInputs = 2 initialInputs = 2
maxInputs = 6 maxInputs = 6
minInputs = 1 minInputs = 1
helpHeight = 5
) )
var ( var (
@ -44,7 +45,6 @@ type keymap = struct {
func newTextarea() textarea.Model { func newTextarea() textarea.Model {
t := textarea.New() t := textarea.New()
t.SetHeight(20)
t.Prompt = "" t.Prompt = ""
t.Placeholder = "Type something" t.Placeholder = "Type something"
t.ShowLineNumbers = true t.ShowLineNumbers = true
@ -63,6 +63,7 @@ func newTextarea() textarea.Model {
type model struct { type model struct {
width int width int
height int
keymap keymap keymap keymap
help help.Model help help.Model
inputs []textarea.Model inputs []textarea.Model
@ -144,6 +145,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
} }
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
m.height = msg.Height
m.width = msg.Width m.width = msg.Width
} }
@ -163,6 +165,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *model) sizeInputs() { func (m *model) sizeInputs() {
for i := range m.inputs { for i := range m.inputs {
m.inputs[i].SetWidth(m.width / len(m.inputs)) m.inputs[i].SetWidth(m.width / len(m.inputs))
m.inputs[i].SetHeight(m.height - helpHeight)
} }
} }
@ -189,7 +192,7 @@ func (m model) View() string {
} }
func main() { func main() {
if err := tea.NewProgram(newModel()).Start(); err != nil { if err := tea.NewProgram(newModel(), tea.WithAltScreen()).Start(); err != nil {
fmt.Println("Error while running program:", err) fmt.Println("Error while running program:", err)
os.Exit(1) os.Exit(1)
} }