From bf5172c17af940494e52ad309f5db3ea6804a6f3 Mon Sep 17 00:00:00 2001 From: Mateusz Drewniak Date: Fri, 28 Jul 2023 17:45:33 +0200 Subject: [PATCH] Rename `GraphemeCount` to `GraphemeCountInString` --- CHANGELOG.md | 5 +++++ buffer.go | 2 +- document.go | 2 +- strings/strings.go | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ffb3f03..638de464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` @@ -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)` diff --git a/buffer.go b/buffer.go index 85b4adde..5ae48152 100644 --- a/buffer.go +++ b/buffer.go @@ -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 { diff --git a/document.go b/document.go index 50f11f79..9ca57f1e 100644 --- a/document.go +++ b/document.go @@ -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 diff --git a/strings/strings.go b/strings/strings.go index 64bccf0d..24ee4f49 100644 --- a/strings/strings.go +++ b/strings/strings.go @@ -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)) }