exp/textinput: add Field.HasText

Closes #3419

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hajime Hoshi
2026-03-21 15:29:10 +09:00
parent 6f32f6bd12
commit 7cd654bf54
2 changed files with 14 additions and 0 deletions
+5
View File
@@ -281,6 +281,11 @@ func (f *Field) TextForRendering() string {
return b.String()
}
// HasText reports whether the field has any text.
func (f *Field) HasText() bool {
return f.pieceTable.hasText()
}
// TextLengthInBytes returns the length of the current text in bytes.
func (f *Field) TextLengthInBytes() int {
return f.pieceTable.Len()
+9
View File
@@ -139,6 +139,15 @@ func (p *pieceTable) writeToWithInsertion(w io.Writer, text string, start, end i
return n, nil
}
func (p *pieceTable) hasText() bool {
for _, item := range p.items() {
if item.start < item.end {
return true
}
}
return false
}
func (p *pieceTable) Len() int {
var n int
items := p.items()