Skip to content

Commit 4510c5f

Browse files
committed
Improve some internal variable/method names in TEditor
1 parent 9474763 commit 4510c5f

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

include/tvision/editors.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class TEditor : public TView
251251
void unlock();
252252
void update( uchar );
253253
void checkScrollBar( const TEvent&, TScrollBar *, int& );
254-
void detectEOL();
254+
void detectEol();
255255

256256
TScrollBar *hScrollBar;
257257
TScrollBar *vScrollBar;
@@ -277,13 +277,13 @@ class TEditor : public TView
277277
Boolean overwrite;
278278
Boolean autoIndent;
279279

280-
enum EOLTypes { eolCRLF, eolLF, eolCR } eolType;
280+
enum EolType { eolCrLf, eolLf, eolCr } eolType;
281+
enum Encoding { encDefault, encSingleByte } encoding;
281282

282-
Boolean encSingleByte;
283283
void nextChar( TStringView, uint &P, uint &width );
284284
Boolean formatCell( TSpan<TScreenCell>, uint&, TStringView, uint& , TColorAttr );
285285
TStringView bufChars( uint );
286-
TStringView bufPrevChars( uint );
286+
TStringView prevBufChars( uint );
287287

288288
static TEditorDialog _NEAR editorDialog;
289289
static ushort _NEAR editorFlags;

source/tvision/edits.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,20 @@ void TEditor::formatLine( TScreenCell *DrawBuf,
5555
char Char = chars[0];
5656
if (Char == '\r' || Char == '\n')
5757
goto fill;
58-
if (Char == '\t') {
59-
if (X < Width) {
60-
do {
58+
if (Char == '\t')
59+
{
60+
if (X < Width)
61+
{
62+
do
63+
{
6164
::setCell(Cells[X++], ' ', Color);
6265
} while (X%8 != 0 && X < Width);
6366
++P;
64-
} else
67+
}
68+
else
6569
break;
66-
} else
70+
}
71+
else
6772
if (!formatCell(Cells, (uint&) X, chars, P, Color))
6873
break;
6974
}
@@ -109,7 +114,7 @@ uint TEditor::nextChar( uint P )
109114
{
110115
if (bufChar(P) == '\r' && bufChar(P + 1) == '\n')
111116
return P + 2;
112-
if (encSingleByte)
117+
if (encoding == encSingleByte)
113118
return P + 1;
114119
else
115120
return P + TText::next(bufChars(P));
@@ -123,11 +128,11 @@ uint TEditor::prevChar( uint P )
123128
{
124129
if (bufChar(P - 2) == '\r' && bufChar(P - 1) == '\n')
125130
return P - 2;
126-
if (encSingleByte)
131+
if (encoding == encSingleByte)
127132
return P - 1;
128133
else
129134
{
130-
TStringView t = bufPrevChars(P);
135+
TStringView t = prevBufChars(P);
131136
return P - TText::prev(t, t.size());
132137
}
133138
}

source/tvision/teditor1.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ TEditor::TEditor( const TRect& bounds,
192192
selecting( False ),
193193
overwrite( False ),
194194
autoIndent( True ) ,
195-
encSingleByte( False ),
195+
encoding( encDefault ),
196196
lockCount( 0 ),
197197
updateFlags( 0 ),
198198
keyState( 0 )
@@ -233,41 +233,41 @@ void TEditor::changeBounds( const TRect& bounds )
233233

234234
TStringView TEditor::bufChars( uint P )
235235
{
236-
static thread_local char buf[4];
237-
if (!encSingleByte)
236+
static thread_local char buf[maxCharLength];
237+
if (encoding == encSingleByte)
238+
{
239+
buf[0] = bufChar(P);
240+
return TStringView(buf, 1);
241+
}
242+
else
238243
{
239244
int len = min(max(max(curPtr, bufLen) - P, 1), sizeof(buf));
240245
for (int i = 0; i < len; ++i)
241246
buf[i] = bufChar(P + i);
242247
return TStringView(buf, len);
243248
}
244-
else
245-
{
246-
buf[0] = bufChar(P);
247-
return TStringView(buf, 1);
248-
}
249249
}
250250

251-
TStringView TEditor::bufPrevChars( uint P )
251+
TStringView TEditor::prevBufChars( uint P )
252252
{
253-
static thread_local char buf[4];
254-
if (!encSingleByte)
253+
static thread_local char buf[maxCharLength];
254+
if (encoding == encSingleByte)
255+
{
256+
buf[0] = bufChar(P - 1);
257+
return TStringView(buf, 1);
258+
}
259+
else
255260
{
256261
int len = min(max(P, 1), sizeof(buf));
257262
for (int i = 0; i < len; ++i)
258263
buf[i] = bufChar(P - len + i);
259264
return TStringView(buf, len);
260265
}
261-
else
262-
{
263-
buf[0] = bufChar(P - 1);
264-
return TStringView(buf, 1);
265-
}
266266
}
267267

268268
void TEditor::nextChar( TStringView s, uint &p, uint &width )
269269
{
270-
if (encSingleByte || !s.size())
270+
if (encoding == encSingleByte || s.size() == 0)
271271
{
272272
++p;
273273
++width;
@@ -618,7 +618,7 @@ void TEditor::handleEvent( TEvent& event )
618618
break;
619619

620620
case evKeyDown:
621-
if( ( !encSingleByte && event.keyDown.textLength > 0 ) ||
621+
if( ( encoding != encSingleByte && event.keyDown.textLength > 0 ) ||
622622
event.keyDown.charScan.charCode == 9 ||
623623
( event.keyDown.charScan.charCode >= 32 && event.keyDown.charScan.charCode < 255 )
624624
)
@@ -637,7 +637,7 @@ void TEditor::handleEvent( TEvent& event )
637637
if( curPtr != lineEnd(curPtr) )
638638
selEnd = nextChar(curPtr);
639639

640-
if( !encSingleByte && event.keyDown.textLength > 0 )
640+
if( encoding != encSingleByte && event.keyDown.textLength > 0 )
641641
insertText( event.keyDown.text, event.keyDown.textLength, False );
642642
else
643643
insertText( &event.keyDown.charScan.charCode, 1, False );

source/tvision/teditor2.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,24 @@ static inline int isWordChar( int ch )
6868

6969
#pragma warn .asc
7070

71-
void TEditor::detectEOL()
71+
void TEditor::detectEol()
7272
{
7373
for (uint p = 0; p < bufLen; ++p)
7474
if (bufChar(p) == '\r')
7575
{
7676
if (p+1 < bufLen && bufChar(p+1) == '\n')
77-
eolType = eolCRLF;
77+
eolType = eolCrLf;
7878
else
79-
eolType = eolCR;
79+
eolType = eolCr;
8080
return;
8181
}
8282
else if (bufChar(p) == '\n')
8383
{
84-
eolType = eolLF;
84+
eolType = eolLf;
8585
return;
8686
}
87-
// Default to CRLF
88-
eolType = eolCRLF;
87+
// Default to CRLF.
88+
eolType = eolCrLf;
8989
}
9090

9191
Boolean TEditor::hasSelection()
@@ -425,7 +425,7 @@ void TEditor::setBufLen( uint length )
425425
delCount = 0;
426426
insCount = 0;
427427
modified = False;
428-
detectEOL();
428+
detectEol();
429429
update(ufView);
430430
}
431431

@@ -555,7 +555,10 @@ void TEditor::startSelect()
555555

556556
void TEditor::toggleEncoding()
557557
{
558-
encSingleByte = Boolean( !encSingleByte );
558+
if( encoding == encDefault )
559+
encoding = encSingleByte;
560+
else
561+
encoding = encDefault;
559562
updateFlags |= ufView;
560563
setSelect(selStart, selEnd, Boolean( curPtr < selEnd ));
561564
}
@@ -633,7 +636,7 @@ void TEditor::write( opstream& os )
633636
TView::write( os );
634637
os << hScrollBar << vScrollBar << indicator
635638
<< bufSize << (uchar)canUndo << (uchar)eolType
636-
<< (uchar)encSingleByte;
639+
<< (uchar)encoding;
637640
}
638641

639642
void *TEditor::read( ipstream& is )
@@ -643,8 +646,8 @@ void *TEditor::read( ipstream& is )
643646
>> bufSize;
644647
uchar temp;
645648
is >> temp; canUndo = Boolean(temp);
646-
is >> temp; eolType = EOLTypes(temp);
647-
is >> temp; encSingleByte = Boolean(temp);
649+
is >> temp; eolType = EolType(temp);
650+
is >> temp; encoding = Encoding(temp);
648651
selecting = False;
649652
overwrite = False;
650653
autoIndent = True;

0 commit comments

Comments
 (0)