@@ -293,9 +293,12 @@ type Model struct {
293
293
// Cursor row.
294
294
row int
295
295
296
- // The bubble offset in the parent model .
296
+ // The bubble offset relative to the parent bubble .
297
297
offsetX , offsetY int
298
298
299
+ // The last recorded real cursor position.
300
+ realCol , realRow int
301
+
299
302
// Last character offset, used to maintain state when the cursor is moved
300
303
// vertically such that we can maintain the same navigating position.
301
304
lastCharOffset int
@@ -383,6 +386,11 @@ func DefaultDarkStyles() Styles {
383
386
return DefaultStyles (true )
384
387
}
385
388
389
+ // SetOffset sets the offset of the textarea relative to the parent bubble.
390
+ func (m * Model ) SetOffset (x , y int ) {
391
+ m .offsetX , m .offsetY = x , y
392
+ }
393
+
386
394
// SetValue sets the value of the text input.
387
395
func (m * Model ) SetValue (s string ) {
388
396
m .Reset ()
@@ -536,11 +544,6 @@ func (m Model) Line() int {
536
544
return m .row
537
545
}
538
546
539
- // SetOffset sets the bubble offset in the parent model.
540
- func (m * Model ) SetOffset (x , y int ) {
541
- m .offsetX , m .offsetY = x , y
542
- }
543
-
544
547
// CursorDown moves the cursor down by one line.
545
548
// Returns whether or not the cursor blink should be reset.
546
549
func (m * Model ) CursorDown () {
@@ -661,6 +664,8 @@ func (m *Model) Reset() {
661
664
m .value = make ([][]rune , minHeight , maxLines )
662
665
m .col = 0
663
666
m .row = 0
667
+ m .realCol = 0
668
+ m .realRow = 0
664
669
m .viewport .GotoTop ()
665
670
m .SetCursor (0 )
666
671
}
@@ -1026,15 +1031,16 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
1026
1031
}
1027
1032
1028
1033
// Need to check for completion before, because key is configurable and might be double assigned
1029
- keyMsg , ok := msg .(tea.KeyMsg )
1030
- if ok && key .Matches (keyMsg , m .KeyMap .AcceptSuggestion ) {
1031
- if m .canAcceptSuggestion () {
1032
- m .value = m .matchedSuggestions [m .currentSuggestionIndex ]
1033
- m .format ()
1034
- m .row = len (m .value ) - 1
1035
- m .CursorEnd ()
1036
- }
1037
- }
1034
+ // keyMsg, ok := msg.(tea.KeyMsg)
1035
+ // if ok && key.Matches(keyMsg, m.KeyMap.AcceptSuggestion) {
1036
+ // if m.canAcceptSuggestion() {
1037
+ // m.value = m.matchedSuggestions[m.currentSuggestionIndex]
1038
+ // m.format()
1039
+ // m.row = len(m.value) - 1
1040
+ // m.CursorEnd()
1041
+ // m.SetSuggestions(nil)
1042
+ // }
1043
+ // }
1038
1044
1039
1045
// Used to determine if the cursor should blink.
1040
1046
oldRow , oldCol := m .cursorLineNumber (), m .col
@@ -1173,11 +1179,23 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
1173
1179
cmds = append (cmds , tea .SetCursorPosition (m .offsetX + newCol , m .offsetY + newRow ))
1174
1180
1175
1181
m .Cursor , cmd = m .Cursor .Update (msg )
1176
- if (newRow != oldRow || newCol != oldCol ) && m .Cursor .Mode () == cursor .CursorBlink {
1182
+ if cmd != nil {
1183
+ cmds = append (cmds , cmd )
1184
+ }
1185
+
1186
+ if m .Cursor .Mode () == cursor .CursorBlink && (newRow != oldRow || newCol != oldCol ) {
1177
1187
m .Cursor .Blink = false
1178
- cmd = m .Cursor .BlinkCmd ()
1188
+ cmds = append (cmds , m .Cursor .BlinkCmd ())
1189
+ }
1190
+
1191
+ // Ensure the real cursor is at the correct position.
1192
+ row := m .cursorLineNumber ()
1193
+ lineInfo := m .LineInfo ()
1194
+ realCol , realRow := m .offsetX + lineInfo .CharOffset , m .offsetY + row - m .viewport .YOffset
1195
+ if realCol != m .realCol || realRow != m .realRow {
1196
+ m .realCol , m .realRow = realCol , realRow
1197
+ cmds = append (cmds , tea .SetCursorPosition (realCol , realRow ))
1179
1198
}
1180
- cmds = append (cmds , cmd )
1181
1199
1182
1200
m .repositionView ()
1183
1201
@@ -1197,7 +1215,7 @@ func (m Model) suggestionView(offset int) string {
1197
1215
1198
1216
var lines []string
1199
1217
for _ , line := range strings .Split (suggestion [len (m .Value ())+ offset :], "\n " ) {
1200
- lines = append (lines , m .style .Placeholder .Inline (true ).Render (line ))
1218
+ lines = append (lines , m .activeStyle .Placeholder .Inline (true ).Render (line ))
1201
1219
}
1202
1220
if len (lines ) > m .Height () {
1203
1221
m .SetHeight (len (lines ) + 1 )
@@ -1217,7 +1235,7 @@ func (m Model) View() string {
1217
1235
style lipgloss.Style
1218
1236
newLines int
1219
1237
widestLineNumber int
1220
- lineInfo = m .LineInfo ()
1238
+ // lineInfo = m.LineInfo()
1221
1239
)
1222
1240
1223
1241
displayLine := 0
@@ -1276,45 +1294,20 @@ func (m Model) View() string {
1276
1294
wrappedLine = []rune (strings .TrimSuffix (string (wrappedLine ), " " ))
1277
1295
padding -= m .width - strwidth
1278
1296
}
1279
- if m .row == l && lineInfo .RowOffset == wl {
1280
- ln := string (wrappedLine [:lineInfo .ColumnOffset ])
1281
- if m .SyntaxHighlighter == nil {
1282
- ln = style .Render (ln )
1283
- } else {
1284
- ln = m .SyntaxHighlighter (ln )
1285
- }
1286
- s .WriteString (ln )
1287
1297
1288
- if m .col >= len (line ) && lineInfo .CharOffset >= m .width {
1289
- m .Cursor .SetChar (" " )
1290
- s .WriteString (m .Cursor .View ())
1291
- // XXX: suggestions?
1292
- } else {
1293
- m .Cursor .SetChar (string (wrappedLine [lineInfo .ColumnOffset ]))
1294
- if m .canAcceptSuggestion () && len (m .matchedSuggestions ) > 0 {
1295
- suggestion := m .matchedSuggestions [m .currentSuggestionIndex ]
1296
- if len (suggestion ) >= m .row {
1297
- suggestion = suggestion [m .row :]
1298
- }
1299
- m .Cursor .TextStyle = m .style .Placeholder
1300
- if len (suggestion ) > m .row && len (suggestion [m .row ]) > m .col {
1301
- m .Cursor .SetChar (string (suggestion [m.row ][m.col ]))
1302
- }
1303
- }
1304
- s .WriteString (style .Render (m .Cursor .View ()))
1305
- s .WriteString (style .Render (string (wrappedLine [lineInfo .ColumnOffset + 1 :])))
1306
- s .WriteString (m .suggestionView (1 ))
1307
- // XXX: suggestions
1308
- }
1298
+ ln = string (wrappedLine )
1299
+ if m .SyntaxHighlighter == nil {
1300
+ ln = style .Render (ln )
1309
1301
} else {
1310
- ln := string (wrappedLine )
1311
- if m .SyntaxHighlighter == nil {
1312
- ln = style .Render (ln )
1313
- } else {
1314
- ln = m .SyntaxHighlighter (ln )
1315
- }
1316
- s .WriteString (ln )
1302
+ ln = m .SyntaxHighlighter (ln )
1317
1303
}
1304
+ s .WriteString (ln )
1305
+
1306
+ // if m.col < len(line) || lineInfo.CharOffset < m.width {
1307
+ // if m.canAcceptSuggestion() && len(m.matchedSuggestions) > 0 {
1308
+ // s.WriteString(m.suggestionView(1))
1309
+ // }
1310
+ // }
1318
1311
1319
1312
pad := strings .Repeat (" " , max (0 , padding ))
1320
1313
if m .SyntaxHighlighter == nil {
0 commit comments