Skip to content

Commit

Permalink
Improve some internal variable/method names in TEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Jan 1, 2024
1 parent 9474763 commit 4510c5f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
8 changes: 4 additions & 4 deletions include/tvision/editors.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class TEditor : public TView
void unlock();
void update( uchar );
void checkScrollBar( const TEvent&, TScrollBar *, int& );
void detectEOL();
void detectEol();

TScrollBar *hScrollBar;
TScrollBar *vScrollBar;
Expand All @@ -277,13 +277,13 @@ class TEditor : public TView
Boolean overwrite;
Boolean autoIndent;

enum EOLTypes { eolCRLF, eolLF, eolCR } eolType;
enum EolType { eolCrLf, eolLf, eolCr } eolType;
enum Encoding { encDefault, encSingleByte } encoding;

Boolean encSingleByte;
void nextChar( TStringView, uint &P, uint &width );
Boolean formatCell( TSpan<TScreenCell>, uint&, TStringView, uint& , TColorAttr );
TStringView bufChars( uint );
TStringView bufPrevChars( uint );
TStringView prevBufChars( uint );

static TEditorDialog _NEAR editorDialog;
static ushort _NEAR editorFlags;
Expand Down
21 changes: 13 additions & 8 deletions source/tvision/edits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ void TEditor::formatLine( TScreenCell *DrawBuf,
char Char = chars[0];
if (Char == '\r' || Char == '\n')
goto fill;
if (Char == '\t') {
if (X < Width) {
do {
if (Char == '\t')
{
if (X < Width)
{
do
{
::setCell(Cells[X++], ' ', Color);
} while (X%8 != 0 && X < Width);
++P;
} else
}
else
break;
} else
}
else
if (!formatCell(Cells, (uint&) X, chars, P, Color))
break;
}
Expand Down Expand Up @@ -109,7 +114,7 @@ uint TEditor::nextChar( uint P )
{
if (bufChar(P) == '\r' && bufChar(P + 1) == '\n')
return P + 2;
if (encSingleByte)
if (encoding == encSingleByte)
return P + 1;
else
return P + TText::next(bufChars(P));
Expand All @@ -123,11 +128,11 @@ uint TEditor::prevChar( uint P )
{
if (bufChar(P - 2) == '\r' && bufChar(P - 1) == '\n')
return P - 2;
if (encSingleByte)
if (encoding == encSingleByte)
return P - 1;
else
{
TStringView t = bufPrevChars(P);
TStringView t = prevBufChars(P);
return P - TText::prev(t, t.size());
}
}
Expand Down
38 changes: 19 additions & 19 deletions source/tvision/teditor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TEditor::TEditor( const TRect& bounds,
selecting( False ),
overwrite( False ),
autoIndent( True ) ,
encSingleByte( False ),
encoding( encDefault ),
lockCount( 0 ),
updateFlags( 0 ),
keyState( 0 )
Expand Down Expand Up @@ -233,41 +233,41 @@ void TEditor::changeBounds( const TRect& bounds )

TStringView TEditor::bufChars( uint P )
{
static thread_local char buf[4];
if (!encSingleByte)
static thread_local char buf[maxCharLength];
if (encoding == encSingleByte)
{
buf[0] = bufChar(P);
return TStringView(buf, 1);
}
else
{
int len = min(max(max(curPtr, bufLen) - P, 1), sizeof(buf));
for (int i = 0; i < len; ++i)
buf[i] = bufChar(P + i);
return TStringView(buf, len);
}
else
{
buf[0] = bufChar(P);
return TStringView(buf, 1);
}
}

TStringView TEditor::bufPrevChars( uint P )
TStringView TEditor::prevBufChars( uint P )
{
static thread_local char buf[4];
if (!encSingleByte)
static thread_local char buf[maxCharLength];
if (encoding == encSingleByte)
{
buf[0] = bufChar(P - 1);
return TStringView(buf, 1);
}
else
{
int len = min(max(P, 1), sizeof(buf));
for (int i = 0; i < len; ++i)
buf[i] = bufChar(P - len + i);
return TStringView(buf, len);
}
else
{
buf[0] = bufChar(P - 1);
return TStringView(buf, 1);
}
}

void TEditor::nextChar( TStringView s, uint &p, uint &width )
{
if (encSingleByte || !s.size())
if (encoding == encSingleByte || s.size() == 0)
{
++p;
++width;
Expand Down Expand Up @@ -618,7 +618,7 @@ void TEditor::handleEvent( TEvent& event )
break;

case evKeyDown:
if( ( !encSingleByte && event.keyDown.textLength > 0 ) ||
if( ( encoding != encSingleByte && event.keyDown.textLength > 0 ) ||
event.keyDown.charScan.charCode == 9 ||
( event.keyDown.charScan.charCode >= 32 && event.keyDown.charScan.charCode < 255 )
)
Expand All @@ -637,7 +637,7 @@ void TEditor::handleEvent( TEvent& event )
if( curPtr != lineEnd(curPtr) )
selEnd = nextChar(curPtr);

if( !encSingleByte && event.keyDown.textLength > 0 )
if( encoding != encSingleByte && event.keyDown.textLength > 0 )
insertText( event.keyDown.text, event.keyDown.textLength, False );
else
insertText( &event.keyDown.charScan.charCode, 1, False );
Expand Down
25 changes: 14 additions & 11 deletions source/tvision/teditor2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ static inline int isWordChar( int ch )

#pragma warn .asc

void TEditor::detectEOL()
void TEditor::detectEol()
{
for (uint p = 0; p < bufLen; ++p)
if (bufChar(p) == '\r')
{
if (p+1 < bufLen && bufChar(p+1) == '\n')
eolType = eolCRLF;
eolType = eolCrLf;
else
eolType = eolCR;
eolType = eolCr;
return;
}
else if (bufChar(p) == '\n')
{
eolType = eolLF;
eolType = eolLf;
return;
}
// Default to CRLF
eolType = eolCRLF;
// Default to CRLF.
eolType = eolCrLf;
}

Boolean TEditor::hasSelection()
Expand Down Expand Up @@ -425,7 +425,7 @@ void TEditor::setBufLen( uint length )
delCount = 0;
insCount = 0;
modified = False;
detectEOL();
detectEol();
update(ufView);
}

Expand Down Expand Up @@ -555,7 +555,10 @@ void TEditor::startSelect()

void TEditor::toggleEncoding()
{
encSingleByte = Boolean( !encSingleByte );
if( encoding == encDefault )
encoding = encSingleByte;
else
encoding = encDefault;
updateFlags |= ufView;
setSelect(selStart, selEnd, Boolean( curPtr < selEnd ));
}
Expand Down Expand Up @@ -633,7 +636,7 @@ void TEditor::write( opstream& os )
TView::write( os );
os << hScrollBar << vScrollBar << indicator
<< bufSize << (uchar)canUndo << (uchar)eolType
<< (uchar)encSingleByte;
<< (uchar)encoding;
}

void *TEditor::read( ipstream& is )
Expand All @@ -643,8 +646,8 @@ void *TEditor::read( ipstream& is )
>> bufSize;
uchar temp;
is >> temp; canUndo = Boolean(temp);
is >> temp; eolType = EOLTypes(temp);
is >> temp; encSingleByte = Boolean(temp);
is >> temp; eolType = EolType(temp);
is >> temp; encoding = Encoding(temp);
selecting = False;
overwrite = False;
autoIndent = True;
Expand Down

0 comments on commit 4510c5f

Please sign in to comment.