* Constructor.
*/
ReLines::ReLines() :
- QStringList(),
- m_empty() {
+ QStringList(),
+ m_empty() {
}
/**
* Destructor.
* <code>false</code>: undo is impossible
*/
void ReLines::insertPart(int lineNo, int col, const QString& text,
- bool withUndo) {
+ bool withUndo) {
if (lineNo >= 0 && lineNo < lineCount() && col >= 0) {
if (withUndo)
storeInsertPart(lineNo, col, text.length());
if (lastEoLn != endOfLine) {
int oldCount = lineCount();
insertLines(lineNo + 1,
- text.mid(endOfLine + 1, lastEoLn - endOfLine), true);
+ text.mid(endOfLine + 1, lastEoLn - endOfLine), true);
newLines = lineCount() - oldCount;
}
if (lastEoLn != text.length() - 1) {
replace(lineNo, current.mid(0, col));
else
replace(lineNo,
- current.mid(0, col) + current.mid(col + count));
+ current.mid(0, col) + current.mid(col + count));
}
}
}
* <code>false</code>: undo is impossible
*/
void ReLines::splitLine(int lineNo, int col, bool withUndo) {
- if (lineNo >= 0 && lineNo < length() && col >= 0) {
+ int count = length();
+ if (lineNo >= 0 && lineNo < count && col >= 0) {
QString current = at(lineNo);
if (withUndo)
storeSplit(lineNo, col);
- int count = length();
- if (lineNo >= count - 1) {
- if (col >= current.length())
+ if (col >= current.length()) {
+ if (lineNo >= count - 1)
append("");
else
- append(current.mid(col));
+ insert(lineNo + 1, "");
} else {
- if (col >= current.length())
- insert(lineNo, "");
+ QString x = current.mid(col);
+ if (lineNo >= count - 1)
+ append(current.mid(col));
else
insert(lineNo + 1, current.mid(col));
+ x = current.mid(0, col);
+ replace(lineNo, current.mid(0, col));
}
- replace(lineNo, current.mid(0, col));
}
}
/**
* @param filename name of the file
*/
ReFile::ReFile(const QString& filename, bool readOnly, ReLogger* logger) :
- ReLineSource(),
- ReLines(),
- m_endOfLine(),
- m_filename(filename),
- m_file(filename),
- m_block(NULL),
- // in 32-bit address space we allocate only 10 MByte, in 64-bit environments 100 GByte
- m_blocksize(
- sizeof(void*) <= 4 ?
- 10 * 1024 * 1024ll : 0x100ll * 0x10000 * 0x10000),
- m_blockOffset(0),
- m_filesize(0),
- m_startOfLine(NULL),
- m_lineLength(0),
- m_lineOffset(0),
- m_currentLineNo(0),
- m_maxLineLength(0x10000),
- m_content(),
- m_readOnly(readOnly),
- m_logger(logger) {
+ ReLineSource(),
+ ReLines(),
+ m_endOfLine(),
+ m_filename(filename),
+ m_file(filename),
+ m_block(NULL),
+ // in 32-bit address space we allocate only 10 MByte, in 64-bit environments 100 GByte
+ m_blocksize(
+ sizeof(void*) <= 4 ?
+ 10 * 1024 * 1024ll : 0x100ll * 0x10000 * 0x10000),
+ m_blockOffset(0),
+ m_filesize(0),
+ m_startOfLine(NULL),
+ m_lineLength(0),
+ m_lineOffset(0),
+ m_currentLineNo(0),
+ m_maxLineLength(0x10000),
+ m_content(),
+ m_readOnly(readOnly),
+ m_logger(logger) {
#if defined __linux__
setEndOfLine("\n");
#elif defined __WIN32__
* false: a line has not been found
*/
bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo,
- QString* line) {
+ QString* line) {
bool rc = false;
int length;
int sourceLength = strlen(toFind);
const char* ptr = start;
int restLength = length - sourceLength + 1;
while (restLength > 0
- && (ptr = reinterpret_cast<const char*>(
- ignoreCase ?
- memchr(start, first, restLength) :
- memichr(start, first, restLength))) != NULL) {
+ && (ptr = reinterpret_cast<const char*>(
+ ignoreCase ?
+ memchr(start, first, restLength) :
+ memichr(start, first, restLength))) != NULL) {
if ((
- ignoreCase ?
- _memicmp(ptr, toFind, sourceLength) :
- memcmp(ptr, toFind, sourceLength)) == 0) {
+ ignoreCase ?
+ _memicmp(ptr, toFind, sourceLength) :
+ memcmp(ptr, toFind, sourceLength)) == 0) {
rc = true;
lineNo = m_currentLineNo;
QByteArray buffer(m_startOfLine, m_lineLength);
* false: a line has not been found
*/
bool ReFile::findLine(const QString& includePattern, bool includeIsRegExpr,
- bool includeIgnoreCase, const QString& excludePattern,
- bool excludeIsRegExpr, bool excludeIgnoreCase, int& lineNo, QString* line) {
+ bool includeIgnoreCase, const QString& excludePattern,
+ bool excludeIsRegExpr, bool excludeIgnoreCase, int& lineNo, QString* line) {
bool rc = false;
if (line != NULL)
*line = "";
if (m_currentLineNo == 65639)
m_currentLineNo += 0;
rc = m_startOfLine = remap(m_lineOffset += m_lineLength,
- m_maxLineLength, lineLength);
+ m_maxLineLength, lineLength);
const char* ptr = reinterpret_cast<const char*>(memchr(rc, '\n',
- lineLength));
+ lineLength));
if (ptr != NULL)
lineLength = ptr - rc + 1;
length = m_lineLength = lineLength;
size = m_filesize - offset;
// Note: size <= m_blocksize
if (m_block != NULL && offset >= m_blockOffset
- && offset + size <= m_blockOffset + m_blocksize) {
+ && offset + size <= m_blockOffset + m_blocksize) {
// new block is inside the internal block:
// no remapping needed
rc = m_block + (offset - m_blockOffset);
if (m_block != NULL)
m_file.unmap(reinterpret_cast<uchar*>(m_block));
m_block = reinterpret_cast<char*>(m_file.map(m_blockOffset,
- m_blocksize));
+ m_blocksize));
rc = m_block + (offset - m_blockOffset);
length = m_blocksize - (rc - m_block);
if (length > size)
* @return the name of an existing directory
*/
QByteArray ReFile::tempDir(const char* node, const char* parent,
- bool withSeparator) {
+ bool withSeparator) {
#if defined __linux__
QByteArray temp("/tmp");
static const char* firstVar = "TMP";
* @return the full name of a temporary file
*/
QByteArray ReFile::tempFile(const char* node, const char* parent,
- bool deleteIfExists) {
+ bool deleteIfExists) {
QByteArray rc(tempDir(parent));
if (!rc.endsWith('/'))
rc += '/';
* @param mode file write mode: "w" (write) or "a" (append)
*/
void ReFile::writeToFile(const char* filename, const char* content,
- size_t contentLength, const char* mode) {
+ size_t contentLength, const char* mode) {
FILE* fp = fopen(filename, mode);
if (fp != NULL) {
if (contentLength == (size_t) - 1)
* Constructor.
*/
ReUndoList::ReUndoList() :
- m_list(),
- m_current(NULL),
- m_lastLine(-1),
- m_lastPosition(-1),
- m_maxUndoSize(10 * 1024 * 1024),
- m_currentUndoSize(0) {
+ m_list(),
+ m_current(NULL),
+ m_lastLine(-1),
+ m_lastPosition(-1),
+ m_maxUndoSize(10 * 1024 * 1024),
+ m_currentUndoSize(0) {
}
/**
* @param list the list containing the lines for extracting the line content
*/
void ReUndoList::storeRemoveLines(int lineNo, int count,
- const QStringList& list) {
+ const QStringList& list) {
qint64 size = 0;
// Calculate the additional space
for (int ii = lineNo + count - 1; ii >= lineNo; ii--)
class TestReEdit: public ReTest, protected ReEdit {
public:
TestReEdit() :
- ReTest("ReEdit"),
- ReEdit(NULL) {
+ ReTest("ReEdit"),
+ ReEdit(NULL) {
doIt();
}
setLines(&m_lines);
}
void pushKey(int key, const QString& text = "",
- Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
QKeyEvent event(QEvent::KeyPress, key, modifiers, text);
keyPressEvent(&event);
}
checkEqu(expectedCol, m_cursorCol);
}
void checkCursorPos(EditorAction action, int expectedLineNo,
- int expectedCol) {
+ int expectedCol) {
editorAction(action);
checkEqu(expectedLineNo, m_cursorLineNo);
checkEqu(expectedCol, m_cursorCol);
m_screenWidth = 5;
m_firstLine = 0;
m_firstCol = 0;
-
// Split line at the end:
m_cursorLineNo = 0;
m_cursorCol = 2;
checkEqu("abc", m_lines.lineAt(0));
checkEqu("", m_lines.lineAt(1));
checkEqu("1234", m_lines.lineAt(2));
-
// Split line in the middle of the line:
m_cursorLineNo = 0;
m_cursorCol = 1;
pushKey(Qt::Key_Enter, "\n");
checkEqu("ab", m_lines.lineAt(0));
checkEqu("c", m_lines.lineAt(1));
- checkEqu("1234", m_lines.lineAt(1));
+ checkEqu("1234", m_lines.lineAt(2));
+
+ // ... in the last line:
+ // Split line at the end:
+ m_cursorLineNo = 2;
+ m_cursorCol = 2;
+ init("abc\n1234\nxy");
+ pushKey(Qt::Key_Return, "\n");
+ checkEqu("xy", m_lines.lineAt(2));
+ checkEqu("", m_lines.lineAt(3));
+ // Split line in the middle of the line:
+ m_cursorLineNo = 2;
+ m_cursorCol = 1;
+ init("abc\n1234\nxyz");
+ pushKey(Qt::Key_Return, "\n");
+ checkEqu("xy", m_lines.lineAt(2));
+ checkEqu("z", m_lines.lineAt(3));
log("ok");
}
* @param source source to copy
*/
inline ReEditText(const ReEditText& source) :
- m_text(source.m_text),
- m_look(source.m_look) {
+ m_text(source.m_text),
+ m_look(source.m_look) {
}
/** Assignment operator.
* @param source source to copy
class ReParagraphBuilder {
public:
virtual void buildParagraph(ReParagraph& paragraph, int lineNo,
- ReEdit* edit);
+ ReEdit* edit);
};
class ReCursortLineBuilder: public ReParagraphBuilder {
// ReParagraphBuilder interface
public:
virtual void buildParagraph(ReParagraph& paragraph, int lineNo,
- ReEdit* edit);
+ ReEdit* edit);
};
/**
class ClickPosition: public QRect {
public:
ClickPosition(ClickObjType type) :
- QRect(0, 0, 0, 0),
- m_type(type),
- m_title(),
- m_object(NULL) {
+ QRect(0, 0, 0, 0),
+ m_type(type),
+ m_title(),
+ m_object(NULL) {
}
public:
bool operator <(const ClickPosition& op) {
EA_VIEW_RIGHT,
EA_PAGE_LEFT,
EA_PAGE_RIGHT,
+ EA_NEWLINE,
};
public:
explicit ReEdit(QWidget *parent = 0);
void editorAction(EditorAction action);
ReLines& lines();
ReLook* lookOf(ReLook::ForeGround foreground,
- ReLook::BackGround background);
+ ReLook::BackGround background);
/** Returns the current page size.
* return number of visible lines in the edit field
*/
protected:
QBrush* createBrush(ReLook::BackGround background);
void drawScrollbars(QPainter& painter, const QRect& rect,
- double sizeVertical, double posVertical, double sizeHorizontal,
- double posHorizontal);
+ double sizeVertical, double posVertical, double sizeHorizontal,
+ double posHorizontal);
void ensureCursorVisible();
protected slots:
void keyPressEvent(QKeyEvent* event);