* Load a text into the textfile viewer. * * This will split the text into newlines and stores it for fast drawing. * * @param buf The text to load. */
| 905 | * @param buf The text to load. |
| 906 | */ |
| 907 | void TextfileWindow::LoadText(std::string_view buf) |
| 908 | { |
| 909 | std::string text = StrMakeValid(buf, {StringValidationSetting::ReplaceWithQuestionMark, StringValidationSetting::AllowNewline, StringValidationSetting::ReplaceTabCrNlWithSpace}); |
| 910 | this->lines.clear(); |
| 911 | |
| 912 | /* Split the string on newlines. */ |
| 913 | std::string_view p(text); |
| 914 | auto next = p.find_first_of('\n'); |
| 915 | while (next != std::string_view::npos) { |
| 916 | this->lines.emplace_back(p.substr(0, next)); |
| 917 | p.remove_prefix(next + 1); |
| 918 | |
| 919 | next = p.find_first_of('\n'); |
| 920 | } |
| 921 | this->lines.emplace_back(p); |
| 922 | |
| 923 | this->AfterLoadText(); |
| 924 | this->ReflowContent(); |
| 925 | |
| 926 | CheckForMissingGlyphs(this); |
| 927 | |
| 928 | /* The font may have changed when searching for glyphs, so ensure widget sizes are updated just in case. */ |
| 929 | this->ReInit(); |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Search a textfile file next to the given content. |
no test coverage detected