Skip to content

Commit

Permalink
exp/textinput: add Field.UncommittedTextLengthInBytes
Browse files Browse the repository at this point in the history
Closes #3174
  • Loading branch information
hajimehoshi committed Dec 26, 2024
1 parent 25b575a commit 25cc679
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exp/textinput/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ func (f *Field) TextForRendering() string {
return f.text
}

// UncommittedTextLengthInBytes returns the compositing text length in bytes when the field is focused and the text is editing.
// The uncommitted text range is from the selection start to the selection start + the uncommitted text length.
// UncommittedTextLengthInBytes returns 0 otherwise.
func (f *Field) UncommittedTextLengthInBytes() int {
if f.IsFocused() {
return len(f.state.Text)
}
return 0
}

// SetTextAndSelection sets the text and the selection range.
func (f *Field) SetTextAndSelection(text string, selectionStartInBytes, selectionEndInBytes int) {
f.cleanUp()
Expand Down

0 comments on commit 25cc679

Please sign in to comment.