forked from qt-creator/qt-creator
CppEditor: use selection(Begin/End) to check local renamings
Instead of relying on the fact that the position < anchor use the appropriate QTextCursor functions that return the required information. Change-Id: I019e714f9f764dea6a613f1072928437d0ebb671 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -243,9 +243,15 @@ void CppLocalRenaming::forgetRenamingSelection()
|
|||||||
m_renameSelectionIndex = -1;
|
m_renameSelectionIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppLocalRenaming::isWithinSelection(const QTextEdit::ExtraSelection &selection, int position)
|
||||||
|
{
|
||||||
|
return selection.cursor.selectionStart() <= position
|
||||||
|
&& position <= selection.cursor.selectionEnd();
|
||||||
|
}
|
||||||
|
|
||||||
bool CppLocalRenaming::isWithinRenameSelection(int position)
|
bool CppLocalRenaming::isWithinRenameSelection(int position)
|
||||||
{
|
{
|
||||||
return renameSelectionBegin() <= position && position <= renameSelectionEnd();
|
return isWithinSelection(renameSelection(), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppLocalRenaming::isSameSelection(int cursorPosition) const
|
bool CppLocalRenaming::isSameSelection(int cursorPosition) const
|
||||||
@@ -254,14 +260,14 @@ bool CppLocalRenaming::isSameSelection(int cursorPosition) const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QTextEdit::ExtraSelection &sel = m_selections[m_renameSelectionIndex];
|
const QTextEdit::ExtraSelection &sel = m_selections[m_renameSelectionIndex];
|
||||||
return (sel.cursor.position() <= cursorPosition && cursorPosition <= sel.cursor.anchor());
|
return isWithinSelection(sel, cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppLocalRenaming::findRenameSelection(int cursorPosition)
|
bool CppLocalRenaming::findRenameSelection(int cursorPosition)
|
||||||
{
|
{
|
||||||
for (int i = 0, total = m_selections.size(); i < total; ++i) {
|
for (int i = 0, total = m_selections.size(); i < total; ++i) {
|
||||||
const QTextEdit::ExtraSelection &sel = m_selections.at(i);
|
const QTextEdit::ExtraSelection &sel = m_selections.at(i);
|
||||||
if (sel.cursor.position() <= cursorPosition && cursorPosition <= sel.cursor.anchor()) {
|
if (isWithinSelection(sel, cursorPosition)) {
|
||||||
m_renameSelectionIndex = i;
|
m_renameSelectionIndex = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -72,11 +72,12 @@ private:
|
|||||||
// The "rename selection" is the local use selection on which the user started the renaming
|
// The "rename selection" is the local use selection on which the user started the renaming
|
||||||
bool findRenameSelection(int cursorPosition);
|
bool findRenameSelection(int cursorPosition);
|
||||||
void forgetRenamingSelection();
|
void forgetRenamingSelection();
|
||||||
|
static bool isWithinSelection(const QTextEdit::ExtraSelection &selection, int position);
|
||||||
bool isWithinRenameSelection(int position);
|
bool isWithinRenameSelection(int position);
|
||||||
|
|
||||||
QTextEdit::ExtraSelection &renameSelection();
|
QTextEdit::ExtraSelection &renameSelection();
|
||||||
int renameSelectionBegin() { return renameSelection().cursor.position(); }
|
int renameSelectionBegin() { return renameSelection().cursor.selectionStart(); }
|
||||||
int renameSelectionEnd() { return renameSelection().cursor.anchor(); }
|
int renameSelectionEnd() { return renameSelection().cursor.selectionEnd(); }
|
||||||
|
|
||||||
void updateRenamingSelectionCursor(const QTextCursor &cursor);
|
void updateRenamingSelectionCursor(const QTextCursor &cursor);
|
||||||
void updateRenamingSelectionFormat(const QTextCharFormat &format);
|
void updateRenamingSelectionFormat(const QTextCharFormat &format);
|
||||||
|
Reference in New Issue
Block a user