From 47ca08717d40cc265dfe8dea0ecdc482c9b288ce Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Sun, 17 Apr 2022 11:21:01 +0300 Subject: [PATCH] bug fixing --- README.md | 6 +++--- imageView.go | 6 ++++++ tableView.go | 6 +++--- textView.go | 22 ++++++++++++++++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e0b9b4f..ecb227c 100644 --- a/README.md +++ b/README.md @@ -538,7 +538,7 @@ For the properties "width", "height", "min-width", "min-height", "max-width", "m func GetMaxWidth(view View, subviewID string) SizeUnit func GetMaxHeight(view View, subviewID string) SizeUnit -### "margin" и "padding" properties +### "margin" and "padding" properties The "margin" property determines the outer margins from this View to its neighbors. The "padding" property sets the padding from the border of the View to the content. @@ -621,7 +621,7 @@ equivalent to view.Set(rui.Margin, rui.Bounds{Top: rui.Px(12), Right: rui.Px(8), Bottom: rui.Px(8), Left: rui.Px(8)}) -### Свойство "border" +### "border" property The "border" property defines a border around the View. The frame line is described by three attributes: line style, thickness and color. @@ -3136,7 +3136,7 @@ The "checkbox" properties allow you to add a checkbox to each item in the list w you can select several items in the list. The "checkbox" int property (ItemCheckbox constant) can take the following values -| Value | Constant | Name | Checkbox view | +| Value | Constant | Name | Checkbox view | |:--------:|------------------|------------|----------------------------------------------------| | 0 | NoneCheckbox | "none" | There is no checkbox. Default value | | 1 | SingleCheckbox | "single" | ◉ A checkbox that allows you to mark only one item | diff --git a/imageView.go b/imageView.go index 0e2eb6d..cfda0fa 100644 --- a/imageView.go +++ b/imageView.go @@ -190,6 +190,12 @@ func (imageView *imageViewData) htmlProperties(self View, buffer *strings.Builde buffer.WriteString(`"`) } } + + if text := GetImageViewAltText(imageView, ""); text != "" { + buffer.WriteString(` alt="`) + buffer.WriteString(textToJS(text)) + buffer.WriteString(`"`) + } } func (imageView *imageViewData) cssStyle(self View, builder cssBuilder) { diff --git a/tableView.go b/tableView.go index 45f86da..03f368b 100644 --- a/tableView.go +++ b/tableView.go @@ -1058,7 +1058,7 @@ func (table *tableViewData) htmlSubviews(self View, buffer *strings.Builder) { switch value := adapter.Cell(row, column).(type) { case string: - buffer.WriteString(value) + buffer.WriteString(textToJS(value)) case View: viewHTML(value, buffer) @@ -1071,10 +1071,10 @@ func (table *tableViewData) htmlSubviews(self View, buffer *strings.Builder) { buffer.WriteString(value.String()) case fmt.Stringer: - buffer.WriteString(value.String()) + buffer.WriteString(textToJS(value.String())) case rune: - buffer.WriteRune(value) + buffer.WriteString(textToJS(string(value))) case float32: buffer.WriteString(fmt.Sprintf("%g", float64(value))) diff --git a/textView.go b/textView.go index cb221bd..c366569 100644 --- a/textView.go +++ b/textView.go @@ -123,16 +123,30 @@ func (textView *textViewData) textOverflowUpdated() { updateCSSProperty(textView.htmlID(), TextOverflow, "", session) } +func textToJS(text string) string { + for _, ch := range []struct{ old, new string }{ + {old: "\\", new: `\\`}, + {old: "\"", new: `\"`}, + {old: "'", new: `\'`}, + {old: "\n", new: `\n`}, + {old: "\r", new: `\r`}, + {old: "\t", new: `\t`}, + {old: "\x00", new: `\x00`}, + } { + if strings.Contains(text, ch.old) { + text = strings.ReplaceAll(text, ch.old, ch.new) + } + } + return text +} + func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) { if value, ok := stringProperty(textView, Text, textView.Session()); ok { if !GetNotTranslate(textView, "") { value, _ = textView.session.GetString(value) } - text := strings.ReplaceAll(value, `"`, `\"`) - text = strings.ReplaceAll(text, "\n", `\n`) - text = strings.ReplaceAll(text, "\r", `\r`) - buffer.WriteString(strings.ReplaceAll(text, `'`, `\'`)) + buffer.WriteString(textToJS(value)) } }