fix prediction: confirm space characters instead of stalling

This commit is contained in:
realrasengan
2026-04-01 18:22:18 -07:00
parent f058c421e7
commit 8e597f7e5d
2 changed files with 28 additions and 1 deletions
+2 -1
View File
@@ -149,8 +149,9 @@ func (p *Predictor) Confirm(fb *Framebuffer) {
if cell.Rune == pred.r {
// Server confirmed this prediction.
confirmed++
} else if cell.Rune == ' ' || cell.Rune == 0 {
} else if (cell.Rune == ' ' || cell.Rune == 0) && pred.r != ' ' {
// Server hasn't caught up yet — stop checking.
// (But if we predicted a space, a space cell is a match, handled above.)
break
} else {
// Server diverged — something unexpected happened
+26
View File
@@ -162,6 +162,32 @@ func TestPredictorExpireStale(t *testing.T) {
}
}
func TestPredictorSpaceConfirm(t *testing.T) {
p := NewPredictor()
p.SetCursor(0, 0)
p.Keystroke([]byte("hi there"))
if len(p.pending) != 8 {
t.Fatalf("expected 8 predictions, got %d", len(p.pending))
}
// Server shows "hi " — space at position 2 should confirm, not stall
fb := NewFramebuffer(80, 24)
fb.CellAt(0, 0).Rune = 'h'
fb.CellAt(1, 0).Rune = 'i'
fb.CellAt(2, 0).Rune = ' '
fb.CurX = 3
fb.CurY = 0
p.Confirm(fb)
if len(p.pending) != 5 {
t.Fatalf("expected 5 pending after confirming 'hi ', got %d", len(p.pending))
}
if p.pending[0].r != 't' {
t.Fatalf("first remaining should be 't', got %c", p.pending[0].r)
}
}
func TestPredictorNoActivityNoCursorOverride(t *testing.T) {
p := NewPredictor()