MCPcopy Create free account
hub / github.com/ZDoom/Raze / InsertText

Method InsertText

libraries/ZWidget/src/widgets/textedit/textedit.cpp:733–774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

731}
732
733void TextEdit::InsertText(ivec2 pos, const std::string& str)
734{
735 undo_info.first_erase = false;
736 if (undo_info.first_text_insert)
737 {
738 undo_info.undo_text = GetText();
739 undo_info.first_text_insert = false;
740 }
741
742 // checking if insert exceeds max length
743 if (ToOffset(ivec2(lines[lines.size() - 1].text.size(), lines.size() - 1)) + str.length() > max_length)
744 {
745 return;
746 }
747
748 std::string::size_type start = 0;
749 while (true)
750 {
751 std::string::size_type next_newline = str.find('\n', start);
752
753 lines[pos.y].text.insert(pos.x, str.substr(start, next_newline - start));
754 lines[pos.y].invalidated = true;
755
756 if (next_newline == std::string::npos)
757 break;
758
759 pos.x += next_newline - start;
760
761 Line line;
762 line.text = lines[pos.y].text.substr(pos.x);
763 lines.insert(lines.begin() + pos.y + 1, line);
764 lines[pos.y].text = lines[pos.y].text.substr(0, pos.x);
765 lines[pos.y].invalidated = true;
766 pos = ivec2(0, pos.y + 1);
767
768 start = next_newline + 1;
769 }
770
771 MoveVerticalScroll();
772
773 Update();
774}
775
776void TextEdit::Backspace()
777{

Callers

nothing calls this directly

Calls 6

ivec2Class · 0.85
lengthMethod · 0.80
sizeMethod · 0.45
findMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected