Skip to content

Commit

Permalink
corrected issues for detecting deleted lines
Browse files Browse the repository at this point in the history
code needed to consider if the selection start and end positions were
at the beginning or end of the line they are at

selection class modified to return status of whether the start and end
selection positions are at the begin or end of the line, replaced
lines() function with newLines(), so if the selection is contained on
a single line, the number of new lines in the selection is zero; also
added comments to the selection class functions
  • Loading branch information
thunder422 committed Feb 16, 2013
1 parent 0742f7e commit c753fd1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
28 changes: 25 additions & 3 deletions editbox.cpp
Expand Up @@ -555,10 +555,32 @@ void EditBox::captureDeletedLines(void)
{
if (!m_beforeSelection.isEmpty() && m_charsRemoved > 0)
{
if (m_beforeSelection.lines() > 1)
if (m_beforeSelection.newLines() > 0)
{
emit linesDeleted(m_beforeSelection.startLine(),
m_beforeSelection.lines() - 1);
int firstLine = m_beforeSelection.startLine();

// if start is not at begin of line
// or start is at end of line and end is not at begin of line
// then don't report first line as deleted
if (!m_beforeSelection.startAtLineBegin()
|| m_beforeSelection.startAtLineEnd()
&& !m_beforeSelection.endAtLineBegin())
{
firstLine++;
}

// if start and end are at begin of line
// or start and end are at end of line
// then current line after deltion should not be set as modified
if (m_beforeSelection.startAtLineBegin()
&& m_beforeSelection.endAtLineBegin()
|| m_beforeSelection.startAtLineEnd()
&& m_beforeSelection.endAtLineEnd())
{
m_lineModified = -1;
}

emit linesDeleted(firstLine, m_beforeSelection.newLines());
}
}
// reset charaters removed and added variables
Expand Down
37 changes: 35 additions & 2 deletions editbox.h
Expand Up @@ -37,35 +37,68 @@ class Selection
int m_end; // end position of selection
int m_startLine; // start line of selection
int m_endLine; // end line of selection
int m_startLineBegin; // position of begin of start line
int m_startLineEnd; // position of end of start line
int m_endLineBegin; // position of begin of end line
int m_endLineEnd; // position of end of end line

public:
Selection(void) {}
// set selction info from a text cursor
void setFromCursor(const QTextCursor &cursor)
{
m_start = cursor.selectionStart();
m_end = cursor.selectionEnd();

QTextBlock block = cursor.document()->findBlock(m_start);
m_startLine = block.blockNumber();
m_startLineBegin = block.position();
m_startLineEnd = m_startLineBegin + block.length() - 1;
block = cursor.document()->findBlock(m_end);
m_endLine = block.blockNumber();
m_endLineBegin = block.position();
m_endLineEnd = m_endLineBegin + block.length() - 1;
}
// return if there is no selection
bool isEmpty(void)
{
return m_start == m_end;
}
int lines(void)
// return number of new lines in selection
int newLines(void)
{
return m_endLine - m_startLine + 1;
return m_endLine - m_startLine;
}
// return start selection line number
int startLine(void)
{
return m_startLine;
}
// return end selection line number
int endLine(void)
{
return m_endLine;
}
// return if start selection position is at the begin of the line
bool startAtLineBegin(void)
{
return m_start == m_startLineBegin;
}
// return if start selection position is at the end of the line
bool startAtLineEnd(void)
{
return m_start == m_startLineEnd;
}
// return if end selection position is at being of the line
bool endAtLineBegin(void)
{
return m_end == m_endLineBegin;
}
// return if end selection position is at end of the line
bool endAtLineEnd(void)
{
return m_end == m_endLineEnd;
}
};


Expand Down

0 comments on commit c753fd1

Please sign in to comment.