@@ -59,6 +59,8 @@ const interruptDebounceTimeout = 1 * time.Second
5959const exitDebounceTimeout = 1 * time .Second
6060
6161type Model struct {
62+ tea.Model
63+ tea.CursorModel
6264 width , height int
6365 app * app.App
6466 modal layout.Modal
@@ -748,15 +750,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
748750 return a , tea .Batch (cmds ... )
749751}
750752
751- func (a Model ) View () string {
753+ func (a Model ) View () ( string , * tea. Cursor ) {
752754 t := theme .CurrentTheme ()
753755
754756 var mainLayout string
755757
758+ var editorX int
759+ var editorY int
756760 if a .app .Session .ID == "" {
757- mainLayout = a .home ()
761+ mainLayout , editorX , editorY = a .home ()
758762 } else {
759- mainLayout = a .chat ()
763+ mainLayout , editorX , editorY = a .chat ()
760764 }
761765 mainLayout = styles .NewStyle ().
762766 Background (t .Background ()).
@@ -780,7 +784,12 @@ func (a Model) View() string {
780784 if theme .CurrentThemeUsesAnsiColors () {
781785 mainLayout = util .ConvertRGBToAnsi16Colors (mainLayout )
782786 }
783- return mainLayout + "\n " + a .status .View ()
787+
788+ cursor := a .editor .Cursor ()
789+ cursor .Position .X += editorX
790+ cursor .Position .Y += editorY
791+
792+ return mainLayout + "\n " + a .status .View (), cursor
784793}
785794
786795func (a Model ) Cleanup () {
@@ -807,7 +816,7 @@ func (a Model) openFile(filepath string) (tea.Model, tea.Cmd) {
807816 return a , cmd
808817}
809818
810- func (a Model ) home () string {
819+ func (a Model ) home () ( string , int , int ) {
811820 t := theme .CurrentTheme ()
812821 effectiveWidth := a .width - 4
813822 baseStyle := styles .NewStyle ().Background (t .Background ())
@@ -899,14 +908,21 @@ func (a Model) home() string {
899908 styles .WhitespaceStyle (t .Background ()),
900909 )
901910
902- editorX := ( effectiveWidth - editorWidth ) / 2
911+ editorX := max ( 0 , ( effectiveWidth - editorWidth )/ 2 )
903912 editorY := (a .height / 2 ) + (mainHeight / 2 ) - 2
904913
905914 if editorLines > 1 {
915+ content := a .editor .Content ()
916+ editorHeight := lipgloss .Height (content )
917+
918+ if editorY + editorHeight > a .height {
919+ difference := (editorY + editorHeight ) - a .height
920+ editorY -= difference
921+ }
906922 mainLayout = layout .PlaceOverlay (
907923 editorX ,
908924 editorY ,
909- a . editor . Content () ,
925+ content ,
910926 mainLayout ,
911927 )
912928 }
@@ -924,10 +940,10 @@ func (a Model) home() string {
924940 )
925941 }
926942
927- return mainLayout
943+ return mainLayout , editorX + 5 , editorY + 2
928944}
929945
930- func (a Model ) chat () string {
946+ func (a Model ) chat () ( string , int , int ) {
931947 effectiveWidth := a .width - 4
932948 t := theme .CurrentTheme ()
933949 editorView := a .editor .View ()
@@ -944,14 +960,20 @@ func (a Model) chat() string {
944960 )
945961
946962 mainLayout := messagesView + "\n " + editorView
947- editorX := (effectiveWidth - editorWidth ) / 2
963+ editorX := max (0 , (effectiveWidth - editorWidth )/ 2 )
964+ editorY := a .height - editorHeight
948965
949966 if lines > 1 {
950- editorY := a .height - editorHeight
967+ content := a .editor .Content ()
968+ editorHeight := lipgloss .Height (content )
969+ if editorY + editorHeight > a .height {
970+ difference := (editorY + editorHeight ) - a .height
971+ editorY -= difference
972+ }
951973 mainLayout = layout .PlaceOverlay (
952974 editorX ,
953975 editorY ,
954- a . editor . Content () ,
976+ content ,
955977 mainLayout ,
956978 )
957979 }
@@ -970,7 +992,7 @@ func (a Model) chat() string {
970992 )
971993 }
972994
973- return mainLayout
995+ return mainLayout , editorX + 5 , editorY + 2
974996}
975997
976998func (a Model ) executeCommand (command commands.Command ) (tea.Model , tea.Cmd ) {
0 commit comments