package editor import ( "strings" "unicode/utf8" ) // WordCount returns the whitespace-separated word count of the whole buffer. func (e *Editor) WordCount() int { n := 0 for _, ln := range e.Lines { n += len(strings.Fields(ln)) } return n } // SelectionStats returns the character and word count of the active selection, // with ok=false when nothing is selected. func (e *Editor) SelectionStats() (chars, words int, ok bool) { if !e.HasSelection() { return 0, 0, false } s := e.SelectedText() return utf8.RuneCountInString(s), len(strings.Fields(s)), true }