Commit 4dffc2aa authored by Erik Verbruggen's avatar Erik Verbruggen

Fixed crash while renaming symbol when a symbol is being renamed.

Task-number: QTCREATORBUG-1770
parent 3b2bd31b
...@@ -369,7 +369,7 @@ CPPEditorEditable::CPPEditorEditable(CPPEditor *editor) ...@@ -369,7 +369,7 @@ CPPEditorEditable::CPPEditorEditable(CPPEditor *editor)
CPPEditor::CPPEditor(QWidget *parent) CPPEditor::CPPEditor(QWidget *parent)
: TextEditor::BaseTextEditor(parent) : TextEditor::BaseTextEditor(parent)
, m_currentRenameSelection(-1) , m_currentRenameSelection(NoCurrentRenameSelection)
, m_inRename(false) , m_inRename(false)
, m_inRenameChanged(false) , m_inRenameChanged(false)
, m_firstRenameChange(false) , m_firstRenameChange(false)
...@@ -490,7 +490,7 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable) ...@@ -490,7 +490,7 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
void CPPEditor::paste() void CPPEditor::paste()
{ {
if (m_currentRenameSelection == -1) { if (m_currentRenameSelection == NoCurrentRenameSelection) {
BaseTextEditor::paste(); BaseTextEditor::paste();
return; return;
} }
...@@ -502,7 +502,7 @@ void CPPEditor::paste() ...@@ -502,7 +502,7 @@ void CPPEditor::paste()
void CPPEditor::cut() void CPPEditor::cut()
{ {
if (m_currentRenameSelection == -1) { if (m_currentRenameSelection == NoCurrentRenameSelection) {
BaseTextEditor::cut(); BaseTextEditor::cut();
return; return;
} }
...@@ -569,10 +569,10 @@ void CPPEditor::finishRename() ...@@ -569,10 +569,10 @@ void CPPEditor::finishRename()
void CPPEditor::abortRename() void CPPEditor::abortRename()
{ {
if (m_currentRenameSelection < 0) if (m_currentRenameSelection <= NoCurrentRenameSelection)
return; return;
m_renameSelections[m_currentRenameSelection].format = m_occurrencesFormat; m_renameSelections[m_currentRenameSelection].format = m_occurrencesFormat;
m_currentRenameSelection = -1; m_currentRenameSelection = NoCurrentRenameSelection;
m_currentRenameSelectionBegin = QTextCursor(); m_currentRenameSelectionBegin = QTextCursor();
m_currentRenameSelectionEnd = QTextCursor(); m_currentRenameSelectionEnd = QTextCursor();
setExtraSelections(CodeSemanticsSelection, m_renameSelections); setExtraSelections(CodeSemanticsSelection, m_renameSelections);
...@@ -777,7 +777,7 @@ void CPPEditor::onContentsChanged(int position, int charsRemoved, int charsAdded ...@@ -777,7 +777,7 @@ void CPPEditor::onContentsChanged(int position, int charsRemoved, int charsAdded
{ {
Q_UNUSED(position) Q_UNUSED(position)
if (m_currentRenameSelection == -1 || m_inRename) if (m_currentRenameSelection == NoCurrentRenameSelection || m_inRename)
return; return;
if (position + charsAdded == m_currentRenameSelectionBegin.position()) { if (position + charsAdded == m_currentRenameSelectionBegin.position()) {
...@@ -934,7 +934,7 @@ void CPPEditor::updateUses() ...@@ -934,7 +934,7 @@ void CPPEditor::updateUses()
void CPPEditor::updateUsesNow() void CPPEditor::updateUsesNow()
{ {
if (m_currentRenameSelection != -1) if (m_currentRenameSelection != NoCurrentRenameSelection)
return; return;
semanticRehighlight(); semanticRehighlight();
...@@ -1505,7 +1505,7 @@ bool CPPEditor::event(QEvent *e) ...@@ -1505,7 +1505,7 @@ bool CPPEditor::event(QEvent *e)
{ {
switch (e->type()) { switch (e->type()) {
case QEvent::ShortcutOverride: case QEvent::ShortcutOverride:
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && m_currentRenameSelection != -1) { if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && m_currentRenameSelection != NoCurrentRenameSelection) {
e->accept(); e->accept();
return true; return true;
} }
...@@ -1568,7 +1568,7 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e) ...@@ -1568,7 +1568,7 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
void CPPEditor::keyPressEvent(QKeyEvent *e) void CPPEditor::keyPressEvent(QKeyEvent *e)
{ {
if (m_currentRenameSelection == -1) { if (m_currentRenameSelection == NoCurrentRenameSelection) {
TextEditor::BaseTextEditor::keyPressEvent(e); TextEditor::BaseTextEditor::keyPressEvent(e);
return; return;
} }
...@@ -1796,6 +1796,7 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) ...@@ -1796,6 +1796,7 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
QList<QTextEdit::ExtraSelection> unusedSelections; QList<QTextEdit::ExtraSelection> unusedSelections;
m_renameSelections.clear(); m_renameSelections.clear();
m_currentRenameSelection = NoCurrentRenameSelection;
SemanticInfo::LocalUseIterator it(semanticInfo.localUses); SemanticInfo::LocalUseIterator it(semanticInfo.localUses);
while (it.hasNext()) { while (it.hasNext()) {
......
...@@ -293,6 +293,7 @@ private: ...@@ -293,6 +293,7 @@ private:
QList<QTextEdit::ExtraSelection> m_renameSelections; QList<QTextEdit::ExtraSelection> m_renameSelections;
int m_currentRenameSelection; int m_currentRenameSelection;
static const int NoCurrentRenameSelection = -1;
bool m_inRename, m_inRenameChanged, m_firstRenameChange; bool m_inRename, m_inRenameChanged, m_firstRenameChange;
QTextCursor m_currentRenameSelectionBegin; QTextCursor m_currentRenameSelectionBegin;
QTextCursor m_currentRenameSelectionEnd; QTextCursor m_currentRenameSelectionEnd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment