Clear this buffer. If it was previously not clear, it has been updated. Otherwise it is just reset to default state. A new buffer is always initially cleared.
| 698 | // Clear this buffer. If it was previously not clear, it has been updated. |
| 699 | // Otherwise it is just reset to default state. A new buffer is always initially cleared. |
| 700 | void ZepBuffer::Clear() { |
| 701 | // A buffer that is empty is brand new; just make it 0 chars and return |
| 702 | if (m_workingBuffer.size() <= 1) { |
| 703 | m_workingBuffer.clear(); |
| 704 | m_workingBuffer.push_back(0); |
| 705 | m_lineEnds.clear(); |
| 706 | m_fileFlags = ZSetFlags(m_fileFlags, FileFlags::TerminatedWithZero); |
| 707 | m_lineEnds.push_back(End().Index() + 1); |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | // Inform clients we are about to change the buffer |
| 712 | GetEditor().Broadcast(std::make_shared<BufferMessage>(this, BufferMessageType::PreBufferChange, GlyphIterator(this), End())); |
| 713 | |
| 714 | m_workingBuffer.clear(); |
| 715 | m_workingBuffer.push_back(0); |
| 716 | m_lineEnds.clear(); |
| 717 | m_fileFlags = ZSetFlags(m_fileFlags, FileFlags::TerminatedWithZero); |
| 718 | m_lineEnds.push_back(End().Index() + 1); |
| 719 | |
| 720 | { |
| 721 | MarkUpdate(); |
| 722 | GetEditor().Broadcast(std::make_shared<BufferMessage>(this, BufferMessageType::TextDeleted, GlyphIterator(this), End())); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // Replace the buffer with the text |
| 727 | void ZepBuffer::SetText(const std::string& text, bool initFromFile) { |