diff --git a/NEWS.md b/NEWS.md index 4fc61614..a3f23259 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,8 +9,8 @@ Red Panda C++ Version 0.13.2 - enhancement: auto update watch, local and memory view after expression evaluated - enhancement: auto update watch, local and memory view after memory modified - enhancement: modify values in the watch view by double click - - + - fix: crash when refactor symbol and cursor is at the end of the identifier + - fix: refactor symbol doesn't work for 1-length identifiers Red Panda C++ Version 0.13.1 - enhancement: suppoort localization info in project templates diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index 9ae8a34b..d92130fb 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -114,16 +114,22 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt editor->parser()->unFreeze(); }); // get full phrase (such as s.name instead of name) - QStringList expression = editor->getExpressionAtPosition(pos); + QStringList expression; + QChar s=editor->charAt(pos); + if (!editor->isIdentChar(s)) { + expression = editor->getExpressionAtPosition(BufferCoord{pos.Char-1,pos.Line}); + } else { + expression = editor->getExpressionAtPosition(pos); + } // Find it's definition PStatement oldStatement = editor->parser()->findStatementOf( editor->filename(), expression, pos.Line); - QString oldScope = fullParentName(oldStatement); // definition of the symbol not found if (!oldStatement) return; + QString oldScope = fullParentName(oldStatement); // found but not in this file if (editor->filename() != oldStatement->fileName || editor->filename() != oldStatement->definitionFileName) { @@ -286,7 +292,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & //same name symbol , test if the same statement; BufferCoord p; p.Line = posY+1; - p.Char = start+1; + p.Char = start; QStringList expression = editor.getExpressionAtPosition(p); PStatement tokenStatement = parser->findStatementOf( diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index d7da9530..87212b38 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -1052,23 +1052,23 @@ QString SynEdit::wordAtCursor() return wordAtRowCol(caretXY()); } -QString SynEdit::wordAtRowCol(const BufferCoord &XY) +QString SynEdit::wordAtRowCol(const BufferCoord &pos) { - if ((XY.Line >= 1) && (XY.Line <= mLines->count())) { - QString line = mLines->getString(XY.Line - 1); - int Len = line.length(); - if (Len == 0) + if ((pos.Line >= 1) && (pos.Line <= mLines->count())) { + QString line = mLines->getString(pos.Line - 1); + int len = line.length(); + if (len == 0) return ""; - if (XY.Char<1 || XY.Char>Len) + if (pos.Char<1 || pos.Char>len) return ""; - int start = XY.Char - 1; + int start = pos.Char - 1; if ((start> 0) && !isIdentChar(line[start])) start--; if (isIdentChar(line[start])) { int stop = start; - while ((stop < Len) && isIdentChar(line[stop])) + while ((stop < len) && isIdentChar(line[stop])) stop++; while ((start-1 >=0) && isIdentChar(line[start - 1])) start--; @@ -1079,6 +1079,20 @@ QString SynEdit::wordAtRowCol(const BufferCoord &XY) return ""; } +QChar SynEdit::charAt(const BufferCoord &pos) +{ + if ((pos.Line >= 1) && (pos.Line <= mLines->count())) { + QString line = mLines->getString(pos.Line-1); + int len = line.length(); + if (len == 0) + return QChar(0); + if (pos.Char<1 || pos.Char>len) + return QChar(0); + return line[pos.Char-1]; + } + return QChar(0); +} + void SynEdit::setCaretAndSelection(const BufferCoord &ptCaret, const BufferCoord &ptBefore, const BufferCoord &ptAfter) { SynSelectionMode vOldMode = mActiveSelectionMode; diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 188fc206..5ddfb7c4 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -211,6 +211,7 @@ public: QString wordAtCursor(); QString wordAtRowCol(const BufferCoord& XY); + QChar charAt(const BufferCoord& pos); int charColumns(QChar ch) const; bool isPointInSelection(const BufferCoord& Value) const;