Skip to content

Commit

Permalink
handle modifications on lines with an error
Browse files Browse the repository at this point in the history
when processing a document change, if only a single line is modified,
the line number of the line is checked to see if it has an error and if
it does, the error will be removed from the errors list if the cursor
is within the error or when the cursor and error is at the end of the
line, or the error column is adjusted if the modification occurs before
the error (no action is take if the cursor is after the error)

to support the adjusting of the error column, new functions were added
to the error list and error item classes
  • Loading branch information
thunder422 committed Jun 15, 2013
1 parent 1508423 commit 98d7b2c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions editbox.cpp
Expand Up @@ -433,6 +433,36 @@ void EditBox::documentChanged(int position, int charsRemoved, int charsAdded)
}
m_lineCount = newLineCount;
}
else // single line modified, reset error if line has an error
{
int errIndex = m_errors.findIndex(changeLine);
if (errIndex != -1)
{
int errCol = m_errors.at(errIndex).column();
int errLen = m_errors.at(errIndex).length();
int col = cursor.positionInBlock();
if (col - charsAdded <= errCol + errLen)
{
// cursor is within or before error
if (cursor.atBlockEnd() && col + charsRemoved >= errCol
|| col - charsAdded + charsRemoved > errCol)
{
// cursor and error at end of line or cursor is within error
// remove error
m_errors.resetChange();
m_errors.removeAt(errIndex);
}
else // cursor is before error, update error
{
m_errors.resetChange();
m_errors.moveColumn(errIndex, charsAdded - charsRemoved);
}
updateErrors(m_errors);
// cause error message to be removed from status line
emit cursorChanged();
}
}
}
m_modifiedLine = m_modifiedLine == -2 ? -1 : cursor.blockNumber();
}

Expand Down
8 changes: 8 additions & 0 deletions errorlist.cpp
Expand Up @@ -147,4 +147,12 @@ void ErrorList::setChangeIndex(int index, Operation operation)
}


// function to move the error due to inserted or deleted characters
void ErrorList::moveColumn(int index, int chars)
{
(*this)[index].moveColumn(chars);
setChangeIndex(index, Change_Operation);
}


// end: errorlist.cpp
5 changes: 5 additions & 0 deletions errorlist.h
Expand Up @@ -63,6 +63,10 @@ class ErrorItem
{
m_lineNumber--;
}
int moveColumn(int chars)
{
m_column += chars;
}
int column(void) const
{
return m_length >= 0 ? m_column : -m_length;
Expand Down Expand Up @@ -97,6 +101,7 @@ class ErrorList : public QList<ErrorItem>
void replace(int index, const ErrorItem &value);
void incrementLineNumber(int index);
void decrementLineNumber(int index);
void moveColumn(int index, int chars);

void resetChange(void)
{
Expand Down

0 comments on commit 98d7b2c

Please sign in to comment.