Skip to content

Commit

Permalink
Rename GraphemeCount to GraphemeCountInString
Browse files Browse the repository at this point in the history
  • Loading branch information
Verseth committed Jul 28, 2023
1 parent 6723651 commit bf5172c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add `strings.GraphemeNumber`, a type that represents the amount of grapheme clusters in a string (or an offset of a grapheme cluster in a string)
- `type strings.GraphemeNumber int`
- `func strings.GraphemeCountInString(text string) strings.GraphemeNumber`
- `func strings.RuneCountInString(s string) strings.RuneNumber`
- `func strings.RuneIndexNthGrapheme(text string, n strings.GraphemeNumber) strings.RuneNumber`
- `func strings.RuneIndexNthColumn(text string, n strings.Width) strings.RuneNumber`
- `func (*prompt.Document).GetCursorLeftPositionRunes(count strings.RuneNumber) strings.RuneNumber`
Expand All @@ -26,6 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Change signatures:
- `strings.RuneCount`
- from `func strings.RuneCount(s string) strings.RuneNumber`
- to `func strings.RuneCount(b []byte) strings.RuneNumber`
- `prompt.ExecuteOnEnterCallback`
- from `func(input string, indentSize int) (indent int, execute bool)`
- to `func(buffer *prompt.Buffer, indentSize int) (indent int, execute bool)`
Expand Down
2 changes: 1 addition & 1 deletion buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (b *Buffer) DeleteBeforeCursor(count istrings.GraphemeNumber, columns istri

textUtf8 := utf8string.NewString(b.Text())
textBeforeCursor := textUtf8.Slice(0, int(b.cursorPosition))
graphemeLength := istrings.GraphemeCount(textBeforeCursor)
graphemeLength := istrings.GraphemeCountInString(textBeforeCursor)

start := istrings.RuneIndexNthGrapheme(textBeforeCursor, graphemeLength-count)
if start < 0 {
Expand Down
2 changes: 1 addition & 1 deletion document.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (d *Document) GetCursorLeftPosition(count istrings.GraphemeNumber) istrings
}
text := d.TextBeforeCursor()
g := uniseg.NewGraphemes(text)
graphemeLength := istrings.GraphemeCount(text)
graphemeLength := istrings.GraphemeCountInString(text)
var currentGraphemeIndex istrings.GraphemeNumber
var currentPosition istrings.RuneNumber

Expand Down
2 changes: 1 addition & 1 deletion strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetWidth(text string) Width {
// Returns the number of horizontal cells needed to print the given
// text. It splits the text into its grapheme clusters, calculates each
// cluster's width, and adds them up to a total.
func GraphemeCount(text string) GraphemeNumber {
func GraphemeCountInString(text string) GraphemeNumber {
return GraphemeNumber(uniseg.GraphemeClusterCount(text))
}

Expand Down

0 comments on commit bf5172c

Please sign in to comment.