@@ -358,13 +358,22 @@ EditBuffer::EditBuffer(TextEditInput *in, const char *text) :
358358 _buffer = (char *)malloc (_size);
359359 memcpy (_buffer, text, _len);
360360 _buffer[_len] = ' \0 ' ;
361+ convertTabs ();
361362 }
362363}
363364
364365EditBuffer::~EditBuffer () {
365366 clear ();
366367}
367368
369+ void EditBuffer::convertTabs () {
370+ for (int i = 0 ; i < _len; i++) {
371+ if (_buffer[i] == ' \t ' ) {
372+ _buffer[i] = ' ' ;
373+ }
374+ }
375+ }
376+
368377void EditBuffer::clear () {
369378 free (_buffer);
370379 _buffer = nullptr ;
@@ -409,6 +418,9 @@ char EditBuffer::getChar(int pos) const {
409418 } else {
410419 result = ' \0 ' ;
411420 }
421+ if (result == ' \r ' ) {
422+ result = ' \n ' ;
423+ }
412424 return result;
413425}
414426
@@ -428,6 +440,7 @@ int EditBuffer::insertChars(int pos, const char *text, int num) {
428440 _len += num;
429441 _buffer[_len] = ' \0 ' ;
430442 _in->setDirty (true );
443+ convertTabs ();
431444 if (num > 1 ) {
432445 _lines += countNewlines (text, num);
433446 } else if (text[0 ] == ' \n ' ) {
@@ -729,8 +742,7 @@ void TextEditInput::dragPage(int y, bool &redraw) {
729742 }
730743}
731744
732- void TextEditInput::drawText (int x, int y, const char *str,
733- int length, SyntaxState &state) {
745+ void TextEditInput::drawText (int x, int y, const char *str, int length, SyntaxState &state) {
734746 int i = 0 ;
735747 int offs = 0 ;
736748 SyntaxState nextState = state;
@@ -1603,10 +1615,10 @@ int TextEditInput::getIndent(char *spaces, int len, int pos) {
16031615
16041616int TextEditInput::getLineChars (StbTexteditRow *row, int pos) const {
16051617 int numChars = row->num_chars ;
1606- if (numChars > 0 && _buf._buffer [pos + row-> num_chars - 1 ] == ' \r ' ) {
1618+ if (numChars > 0 && _buf._buffer [pos + numChars - 1 ] == ' \n ' ) {
16071619 numChars--;
16081620 }
1609- if (numChars > 0 && _buf._buffer [pos + row-> num_chars - 1 ] == ' \n ' ) {
1621+ if (numChars > 0 && _buf._buffer [pos + numChars - 1 ] == ' \r ' ) {
16101622 numChars--;
16111623 }
16121624 return numChars;
0 commit comments