TVision
view release on metacpan or search on metacpan
tvision.git/source/tvision/teditor2.cpp view on Meta::CPAN
if( length > 0 )
memmove(
&buffer[curPtr],
&p[offset],
length
);
uint lines = countLines( &buffer[curPtr], length );
curPtr += length;
curPos.y += lines;
drawLine = curPos.y;
drawPtr = lineStart(curPtr);
curPos.x = charPos(drawPtr, curPtr);
if( selectText == False )
selStart = curPtr;
selEnd = curPtr;
bufLen += length - selLen;
gapLen -= length - selLen;
if( allowUndo == True )
{
delCount += delLen;
insCount += length;
}
limit.y += lines - selLines;
delta.y = max(0, min(delta.y, limit.y - size.y));
if( isClipboard() == False )
modified = True;
setBufSize(bufLen + delCount);
if( selLines == 0 && lines == 0 )
update(ufLine);
else
update(ufView);
return True;
}
Boolean TEditor::insertEOL( Boolean selectText )
{
static const char * const eolBytes[] = { "\r\n", "\n", "\r" };
const char *eol = eolBytes[eolType];
return insertText( eol, strlen(eol), selectText );
}
Boolean TEditor::insertFrom( TEditor *editor )
{
return insertBuffer( editor->buffer,
editor->bufPtr(editor->selStart),
editor->selEnd - editor->selStart,
canUndo,
isClipboard()
);
}
Boolean TEditor::insertText( const void *text, uint length, Boolean selectText )
{
return insertBuffer( (const char *)text, 0, length, canUndo, selectText);
}
Boolean TEditor::isClipboard()
{
return Boolean(clipboard == this);
}
uint TEditor::lineMove( uint p, int count )
{
uint i = p;
p = lineStart(p);
int pos = charPos(p, i);
while( count != 0 )
{
i = p;
if( count < 0 )
{
p = prevLine(p);
count++;
}
else
{
p = nextLine(p);
count--;
}
}
if( p != i )
p = charPtr(p, pos);
return p;
}
void TEditor::lock()
{
lockCount++;
}
void TEditor::newLine()
{
uint p = lineStart(curPtr);
uint i = p;
while( i < curPtr &&
( (buffer[i] == ' ') || (buffer[i] == '\x9'))
)
i++;
insertEOL(False);
if( autoIndent == True )
insertText( &buffer[p], i - p, False);
}
uint TEditor::nextLine( uint p )
{
return nextChar(lineEnd(p));
}
uint TEditor::nextWord( uint p )
{
if (p < bufLen)
{
char a = bufChar(p);
char b;
do {
b = a;
p = nextChar(p);
} while( p < bufLen && !isWordBoundary((a = bufChar(p)), b) );
}
tvision.git/source/tvision/teditor2.cpp view on Meta::CPAN
encoding = encSingleByte;
else
encoding = encDefault;
updateFlags |= ufView;
setSelect(selStart, selEnd, Boolean( curPtr < selEnd ));
}
void TEditor::toggleInsMode()
{
overwrite = Boolean(!overwrite);
setState(sfCursorIns, Boolean(!getState(sfCursorIns)));
}
void TEditor::trackCursor( Boolean center )
{
if( center == True )
scrollTo( curPos.x - size.x + 1, curPos.y - size.y / 2);
else
scrollTo( max(curPos.x - size.x + 1, min(delta.x, curPos.x)),
max(curPos.y - size.y + 1, min(delta.y, curPos.y)));
}
void TEditor::undo()
{
if( delCount != 0 || insCount != 0 )
{
selStart = curPtr - insCount;
selEnd = curPtr;
uint length = delCount;
delCount = 0;
insCount = 0;
insertBuffer(buffer, curPtr + gapLen - length, length, False, True);
}
}
void TEditor::unlock()
{
if( lockCount > 0 )
{
lockCount--;
if( lockCount == 0 )
doUpdate();
}
}
void TEditor::update( uchar aFlags )
{
updateFlags |= aFlags;
if( lockCount == 0 )
doUpdate();
}
void TEditor::updateCommands()
{
setCmdState( cmUndo, Boolean( delCount != 0 || insCount != 0 ) );
if( isClipboard() == False )
{
setCmdState(cmCut, hasSelection());
setCmdState(cmCopy, hasSelection());
setCmdState(cmPaste,
Boolean(clipboard == 0 || clipboard->hasSelection()) );
}
setCmdState(cmClear, hasSelection());
setCmdState(cmFind, True);
setCmdState(cmReplace, True);
setCmdState(cmSearchAgain, True);
}
Boolean TEditor::valid( ushort )
{
return isValid;
}
#if !defined(NO_STREAMABLE)
void TEditor::write( opstream& os )
{
TView::write( os );
os << hScrollBar << vScrollBar << indicator
<< bufSize << (uchar)canUndo << (uchar)eolType
<< (uchar)encoding;
}
void *TEditor::read( ipstream& is )
{
TView::read( is );
is >> hScrollBar >> vScrollBar >> indicator
>> bufSize;
uchar temp;
is >> temp; canUndo = Boolean(temp);
is >> temp; eolType = EolType(temp);
is >> temp; encoding = Encoding(temp);
selecting = False;
overwrite = False;
autoIndent = True;
lockCount = 0;
updateFlags = 0;
keyState = 0;
initBuffer();
if( buffer != 0 )
isValid = True;
else
{
isValid = False;
TEditor::editorDialog( edOutOfMemory, 0 );
bufSize = 0;
}
lockCount = 0;
lock();
setBufLen( 0 );
return this;
}
TStreamable *TEditor::build()
{
return new TEditor( streamableInit );
}
TEditor::TEditor( StreamableInit ) noexcept : TView( streamableInit )
{
}
( run in 1.802 second using v1.01-cache-2.11-cpan-2398b32b56e )