MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / Insert

Method Insert

external/zep/src/buffer.cpp:897–959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

895 }
896
897 bool ZepBuffer::Insert(const GlyphIterator& startIndex, const std::string& str, ChangeRecord& changeRecord) {
898 if (!startIndex.Valid()) {
899 return false;
900 }
901
902 GlyphIterator endIndex(this, startIndex.Index() + long(str.length()));
903
904 sigPreInsert(*this, startIndex, str);
905
906 // We are about to modify this range
907 // TODO: Is this correct, and/or useful in any way??
908 // We aren't changing this range at all; we are shifting those characters forward and replacing the area
909 GetEditor().Broadcast(std::make_shared<BufferMessage>(this, BufferMessageType::PreBufferChange, startIndex, endIndex));
910
911 // abcdef\r\nabc<insert>dfdf\r\n
912 auto itrLine = std::lower_bound(m_lineEnds.begin(), m_lineEnds.end(), startIndex.Index());
913 ;
914 if (itrLine != m_lineEnds.end() && *itrLine <= startIndex.Index()) {
915 itrLine++;
916 }
917
918 auto itrEnd = str.end();
919 auto itrBegin = str.begin();
920 auto itr = str.begin();
921
922 // Make a list of lines to 'insert'
923 std::vector<long> lines;
924 std::string lineEndSymbols("\n");
925 while (itr != itrEnd) {
926 // Get to first point after "\n"
927 // That's the point just after the end of the current line
928 itr = std::find_first_of(itr, itrEnd, lineEndSymbols.begin(), lineEndSymbols.end());
929 if (itr != itrEnd) {
930 if (itr != itrEnd && *itr == '\n') {
931 itr++;
932 }
933 lines.push_back(long(itr - itrBegin) + startIndex.Index());
934 }
935 }
936
937 // Increment the rest of the line ends
938 // We make all the remaning line ends bigger by the fixed_size of the insertion
939 auto itrAdd = itrLine;
940 while (itrAdd != m_lineEnds.end()) {
941 *itrAdd += long(str.length());
942 itrAdd++;
943 }
944
945 if (!lines.empty()) {
946 // Update the atomic line counter so clients can see where we are up to.
947 m_lineEnds.insert(itrLine, lines.begin(), lines.end());
948 }
949
950 changeRecord.strInserted = str;
951 m_workingBuffer.insert(m_workingBuffer.begin() + startIndex.Index(), str.begin(), str.end());
952
953 MarkUpdate();
954

Callers 6

applyCompletionMethod · 0.45
PromptMethod · 0.45
AddKeyPressMethod · 0.45
BuildTreeMethod · 0.45
UndoMethod · 0.45
RedoMethod · 0.45

Calls 9

ValidMethod · 0.80
IndexMethod · 0.80
lengthMethod · 0.80
BroadcastMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected