fix: use real cursor instead of virtual cursor
This commit is contained in:
@@ -31,6 +31,7 @@ type EditorComponent interface {
|
|||||||
tea.Model
|
tea.Model
|
||||||
tea.ViewModel
|
tea.ViewModel
|
||||||
Content() string
|
Content() string
|
||||||
|
Cursor() *tea.Cursor
|
||||||
Lines() int
|
Lines() int
|
||||||
Value() string
|
Value() string
|
||||||
Length() int
|
Length() int
|
||||||
@@ -407,6 +408,10 @@ func (m *editorComponent) Content() string {
|
|||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *editorComponent) Cursor() *tea.Cursor {
|
||||||
|
return m.textarea.Cursor()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *editorComponent) View() string {
|
func (m *editorComponent) View() string {
|
||||||
width := m.width
|
width := m.width
|
||||||
if m.app.Session.ID == "" {
|
if m.app.Session.ID == "" {
|
||||||
@@ -694,6 +699,7 @@ func NewEditorComponent(app *app.App) EditorComponent {
|
|||||||
ta.Prompt = " "
|
ta.Prompt = " "
|
||||||
ta.ShowLineNumbers = false
|
ta.ShowLineNumbers = false
|
||||||
ta.CharLimit = -1
|
ta.CharLimit = -1
|
||||||
|
ta.VirtualCursor = false
|
||||||
ta = updateTextareaStyles(ta)
|
ta = updateTextareaStyles(ta)
|
||||||
|
|
||||||
m := &editorComponent{
|
m := &editorComponent{
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ const interruptDebounceTimeout = 1 * time.Second
|
|||||||
const exitDebounceTimeout = 1 * time.Second
|
const exitDebounceTimeout = 1 * time.Second
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
|
tea.Model
|
||||||
|
tea.CursorModel
|
||||||
width, height int
|
width, height int
|
||||||
app *app.App
|
app *app.App
|
||||||
modal layout.Modal
|
modal layout.Modal
|
||||||
@@ -748,15 +750,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return a, tea.Batch(cmds...)
|
return a, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Model) View() string {
|
func (a Model) View() (string, *tea.Cursor) {
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
|
|
||||||
var mainLayout string
|
var mainLayout string
|
||||||
|
|
||||||
|
var editorX int
|
||||||
|
var editorY int
|
||||||
if a.app.Session.ID == "" {
|
if a.app.Session.ID == "" {
|
||||||
mainLayout = a.home()
|
mainLayout, editorX, editorY = a.home()
|
||||||
} else {
|
} else {
|
||||||
mainLayout = a.chat()
|
mainLayout, editorX, editorY = a.chat()
|
||||||
}
|
}
|
||||||
mainLayout = styles.NewStyle().
|
mainLayout = styles.NewStyle().
|
||||||
Background(t.Background()).
|
Background(t.Background()).
|
||||||
@@ -780,7 +784,12 @@ func (a Model) View() string {
|
|||||||
if theme.CurrentThemeUsesAnsiColors() {
|
if theme.CurrentThemeUsesAnsiColors() {
|
||||||
mainLayout = util.ConvertRGBToAnsi16Colors(mainLayout)
|
mainLayout = util.ConvertRGBToAnsi16Colors(mainLayout)
|
||||||
}
|
}
|
||||||
return mainLayout + "\n" + a.status.View()
|
|
||||||
|
cursor := a.editor.Cursor()
|
||||||
|
cursor.Position.X += editorX
|
||||||
|
cursor.Position.Y += editorY
|
||||||
|
|
||||||
|
return mainLayout + "\n" + a.status.View(), cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Model) Cleanup() {
|
func (a Model) Cleanup() {
|
||||||
@@ -807,7 +816,7 @@ func (a Model) openFile(filepath string) (tea.Model, tea.Cmd) {
|
|||||||
return a, cmd
|
return a, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Model) home() string {
|
func (a Model) home() (string, int, int) {
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
effectiveWidth := a.width - 4
|
effectiveWidth := a.width - 4
|
||||||
baseStyle := styles.NewStyle().Background(t.Background())
|
baseStyle := styles.NewStyle().Background(t.Background())
|
||||||
@@ -899,14 +908,21 @@ func (a Model) home() string {
|
|||||||
styles.WhitespaceStyle(t.Background()),
|
styles.WhitespaceStyle(t.Background()),
|
||||||
)
|
)
|
||||||
|
|
||||||
editorX := (effectiveWidth - editorWidth) / 2
|
editorX := max(0, (effectiveWidth-editorWidth)/2)
|
||||||
editorY := (a.height / 2) + (mainHeight / 2) - 2
|
editorY := (a.height / 2) + (mainHeight / 2) - 2
|
||||||
|
|
||||||
if editorLines > 1 {
|
if editorLines > 1 {
|
||||||
|
content := a.editor.Content()
|
||||||
|
editorHeight := lipgloss.Height(content)
|
||||||
|
|
||||||
|
if editorY+editorHeight > a.height {
|
||||||
|
difference := (editorY + editorHeight) - a.height
|
||||||
|
editorY -= difference
|
||||||
|
}
|
||||||
mainLayout = layout.PlaceOverlay(
|
mainLayout = layout.PlaceOverlay(
|
||||||
editorX,
|
editorX,
|
||||||
editorY,
|
editorY,
|
||||||
a.editor.Content(),
|
content,
|
||||||
mainLayout,
|
mainLayout,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -924,10 +940,10 @@ func (a Model) home() string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainLayout
|
return mainLayout, editorX + 5, editorY + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Model) chat() string {
|
func (a Model) chat() (string, int, int) {
|
||||||
effectiveWidth := a.width - 4
|
effectiveWidth := a.width - 4
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
editorView := a.editor.View()
|
editorView := a.editor.View()
|
||||||
@@ -944,14 +960,20 @@ func (a Model) chat() string {
|
|||||||
)
|
)
|
||||||
|
|
||||||
mainLayout := messagesView + "\n" + editorView
|
mainLayout := messagesView + "\n" + editorView
|
||||||
editorX := (effectiveWidth - editorWidth) / 2
|
editorX := max(0, (effectiveWidth-editorWidth)/2)
|
||||||
|
editorY := a.height - editorHeight
|
||||||
|
|
||||||
if lines > 1 {
|
if lines > 1 {
|
||||||
editorY := a.height - editorHeight
|
content := a.editor.Content()
|
||||||
|
editorHeight := lipgloss.Height(content)
|
||||||
|
if editorY+editorHeight > a.height {
|
||||||
|
difference := (editorY + editorHeight) - a.height
|
||||||
|
editorY -= difference
|
||||||
|
}
|
||||||
mainLayout = layout.PlaceOverlay(
|
mainLayout = layout.PlaceOverlay(
|
||||||
editorX,
|
editorX,
|
||||||
editorY,
|
editorY,
|
||||||
a.editor.Content(),
|
content,
|
||||||
mainLayout,
|
mainLayout,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -970,7 +992,7 @@ func (a Model) chat() string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainLayout
|
return mainLayout, editorX + 5, editorY + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
||||||
|
|||||||
Reference in New Issue
Block a user