diff options
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r-- | src/CellBuffer.cxx | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index de499ad68..d349040f0 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -44,9 +44,11 @@ void LineVector::InsertText(int line, int delta) { starts.InsertText(line, delta); } -void LineVector::InsertLine(int line, int position) { +void LineVector::InsertLine(int line, int position, bool lineStart) { starts.InsertPartition(line, position); if (perLine) { + if ((line > 0) && lineStart) + line--; perLine->InsertLine(line); } } @@ -473,8 +475,8 @@ bool CellBuffer::IsSavePoint() { // Without undo -void CellBuffer::InsertLine(int line, int position) { - lv.InsertLine(line, position); +void CellBuffer::InsertLine(int line, int position, bool lineStart) { + lv.InsertLine(line, position, lineStart); } void CellBuffer::RemoveLine(int line) { @@ -490,30 +492,32 @@ void CellBuffer::BasicInsertString(int position, const char *s, int insertLength style.InsertValue(position, insertLength, 0); int lineInsert = lv.LineFromPosition(position) + 1; + bool atLineStart = lv.LineStart(lineInsert-1) == position; // Point all the lines after the insertion point further along in the buffer lv.InsertText(lineInsert-1, insertLength); char chPrev = substance.ValueAt(position - 1); char chAfter = substance.ValueAt(position + insertLength); if (chPrev == '\r' && chAfter == '\n') { // Splitting up a crlf pair at position - InsertLine(lineInsert, position); + InsertLine(lineInsert, position, false); lineInsert++; } char ch = ' '; for (int i = 0; i < insertLength; i++) { ch = s[i]; if (ch == '\r') { - InsertLine(lineInsert, (position + i) + 1); + InsertLine(lineInsert, (position + i) + 1, atLineStart); lineInsert++; } else if (ch == '\n') { if (chPrev == '\r') { // Patch up what was end of line lv.SetLineStart(lineInsert - 1, (position + i) + 1); } else { - InsertLine(lineInsert, (position + i) + 1); + InsertLine(lineInsert, (position + i) + 1, atLineStart); lineInsert++; } } + atLineStart = false; chPrev = ch; } // Joining two lines where last insertion is cr and following substance starts with lf |