diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CellBuffer.cxx | 25 | ||||
-rw-r--r-- | src/CellBuffer.h | 3 | ||||
-rw-r--r-- | src/Document.h | 5 | ||||
-rw-r--r-- | src/Editor.cxx | 4 |
4 files changed, 23 insertions, 14 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 6dae67507..f6c1f7b17 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -627,21 +627,11 @@ void CellBuffer::RoomFor(int insertionLength) { //Platform::DebugPrintf("need room %d %d\n", gaplen, insertionLength); if (gaplen <= insertionLength) { //Platform::DebugPrintf("need room %d %d\n", gaplen, insertionLength); - GapTo(length); if (growSize * 6 < size) growSize *= 2; int newSize = size + insertionLength + growSize; - //Platform::DebugPrintf("moved gap %d\n", newSize); - char *newBody = new char[newSize]; - memcpy(newBody, body, size); - delete []body; - body = newBody; - gaplen += newSize - size; - part2body = body + gaplen; - size = newSize; - //Platform::DebugPrintf("end need room %d %d - size=%d length=%d\n", gaplen, insertionLength,size,length); + Allocate(newSize); } - } // To make it easier to write code that uses ByteAt, a position outside the range of the buffer @@ -791,6 +781,19 @@ int CellBuffer::Length() { return ByteLength() / 2; } +void CellBuffer::Allocate(int newSize) { + if (newSize > size) { + GapTo(length); + char *newBody = new char[newSize]; + memcpy(newBody, body, size); + delete []body; + body = newBody; + gaplen += newSize - size; + part2body = body + gaplen; + size = newSize; + } +} + int CellBuffer::Lines() { //Platform::DebugPrintf("Lines = %d\n", lv.lines); return lv.lines; diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 5cfcbfe1f..726ec015f 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -184,6 +184,7 @@ public: int ByteLength(); int Length(); + void Allocate(int newSize); int Lines(); int LineStart(int line); int LineFromPosition(int pos) { return lv.LineFromPosition(pos); } @@ -212,7 +213,7 @@ public: int GetMark(int line); void DeleteAllMarks(int markerNum); int LineFromHandle(int markerHandle); - + /// Actions without undo void BasicInsertString(int position, char *s, int insertLength); void BasicDeleteChars(int position, int deleteLength); diff --git a/src/Document.h b/src/Document.h index f5436ab4f..18b47eaf5 100644 --- a/src/Document.h +++ b/src/Document.h @@ -87,7 +87,7 @@ public: userData = 0; } }; - + enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation }; private: @@ -193,6 +193,7 @@ public: int NextWordStart(int pos, int delta); int NextWordEnd(int pos, int delta); int Length() { return cb.Length(); } + void Allocate(int newSize) { cb.Allocate(newSize*2); } long FindText(int minPos, int maxPos, const char *s, bool caseSensitive, bool word, bool wordStart, bool regExp, bool posix, int *length); long FindText(int iMessage, unsigned long wParam, long lParam); @@ -200,7 +201,7 @@ public: int LinesTotal(); void ChangeCase(Range r, bool makeUpperCase); - + void SetDefaultCharClasses(); void SetCharClasses(unsigned char *chars, charClassification newCharClass); void SetStylingBits(int bits); diff --git a/src/Editor.cxx b/src/Editor.cxx index f9d20aa47..a11f99688 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5788,6 +5788,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETLENGTH: return pdoc->Length(); + case SCI_ALLOCATE: + pdoc->Allocate(wParam); + break; + case SCI_GETCHARAT: return pdoc->CharAt(wParam); |