From 5962c4c9a7e5ed9be541cafe46af662dc30d192d Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 15 Feb 2022 15:59:26 +0100 Subject: [PATCH] Added TextView.GetOriginalLineCount(). --- textview.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/textview.go b/textview.go index b133d17..c60ae82 100644 --- a/textview.go +++ b/textview.go @@ -323,9 +323,10 @@ func (t *TextView) SetText(text string) *TextView { // to true, any region/color tags are stripped from the text. func (t *TextView) GetText(stripAllTags bool) string { // Get the buffer. - buffer := make([]string, len(t.buffer), len(t.buffer)+1) - copy(buffer, t.buffer) + buffer := t.buffer if !stripAllTags { + buffer = make([]string, len(t.buffer), len(t.buffer)+1) + copy(buffer, t.buffer) buffer = append(buffer, string(t.recentBytes)) } @@ -348,6 +349,12 @@ func (t *TextView) GetText(stripAllTags bool) string { return text } +// GetOriginalLineCount returns the number of lines in the original text buffer, +// i.e. the number of newline characters plus one. +func (t *TextView) GetOriginalLineCount() int { + return len(t.buffer) +} + // SetDynamicColors sets the flag that allows the text color to be changed // dynamically. See class description for details. func (t *TextView) SetDynamicColors(dynamic bool) *TextView {