- fix: crash when refactor symbol and cursor is at the end of the identifier
- fix: refactor symbol doesn't work for 1-length identifiers
This commit is contained in:
parent
d8413ab76c
commit
995b734334
4
NEWS.md
4
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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue