Merge pull request #53 from BalazsJako/dev
Merling changes to master.
diff --git a/TextEditor.cpp b/TextEditor.cpp
index 73b12b7..85e21fe 100644
--- a/TextEditor.cpp
+++ b/TextEditor.cpp
@@ -825,7 +825,7 @@
void TextEditor::SetText(const std::string & aText)
{
mLines.clear();
- mLines.push_back(Line());
+ mLines.emplace_back(Line());
for (auto chr : aText)
{
if (chr == '\r')
@@ -833,10 +833,10 @@
// ignore the carriage return character
}
else if (chr == '\n')
- mLines.push_back(Line());
+ mLines.emplace_back(Line());
else
{
- mLines.back().push_back(Glyph(chr, PaletteIndex::Default));
+ mLines.back().emplace_back(Glyph(chr, PaletteIndex::Default));
}
mTextChanged = true;
@@ -846,6 +846,35 @@
Colorize();
}
+
+void TextEditor::SetTextLines(const std::vector<std::string> & aLines)
+{
+ mLines.clear();
+
+ if (aLines.empty())
+ {
+ mLines.emplace_back(Line());
+ }
+ else
+ {
+ mLines.resize(aLines.size());
+
+ for (size_t i = 0; i < aLines.size(); ++i)
+ {
+ const std::string & aLine = aLines[i];
+
+ mLines[i].reserve(aLine.size());
+ for (size_t j = 0; j < aLine.size(); ++j)
+ mLines[i].emplace_back(Glyph(aLine[j], PaletteIndex::Default));
+ }
+ }
+
+ mTextChanged = true;
+
+ mUndoBuffer.clear();
+
+ Colorize();
+}
void TextEditor::EnterCharacter(Char aChar, bool aShift)
{
@@ -1625,6 +1654,27 @@
std::string TextEditor::GetText() const
{
return GetText(Coordinates(), Coordinates((int)mLines.size(), 0));
+}
+
+std::vector<std::string> TextEditor::GetTextLines() const
+{
+ std::vector<std::string> result;
+
+ result.reserve(mLines.size());
+
+ for (auto & line : mLines)
+ {
+ std::string text;
+
+ text.resize(line.size());
+
+ for (size_t i = 0; i < line.size(); ++i)
+ text[i] = line[i].mChar;
+
+ result.emplace_back(std::move(text));
+ }
+
+ return result;
}
std::string TextEditor::GetSelectedText() const
diff --git a/TextEditor.h b/TextEditor.h
index 918a0c2..9ea838d 100644
--- a/TextEditor.h
+++ b/TextEditor.h
@@ -184,8 +184,10 @@
void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }
void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false);
- void SetText(const std::string& aText);
- std::string GetText() const;
+ void SetText(const std::string& aText);
+ void SetTextLines(const std::vector<std::string>& aLines);
+ std::string GetText() const;
+ std::vector<std::string> GetTextLines() const;
std::string GetSelectedText() const;
std::string GetCurrentLineText()const;