forked from qt-creator/qt-creator
Use 1-based locations.
This commit is contained in:
@@ -93,9 +93,10 @@ public:
|
|||||||
Document::Ptr targetDoc = changes->document(m_targetFileName);
|
Document::Ptr targetDoc = changes->document(m_targetFileName);
|
||||||
InsertionPointLocator locator(targetDoc);
|
InsertionPointLocator locator(targetDoc);
|
||||||
const InsertionLocation loc = locator.methodDeclarationInClass(m_targetSymbol, InsertionPointLocator::Public);
|
const InsertionLocation loc = locator.methodDeclarationInClass(m_targetSymbol, InsertionPointLocator::Public);
|
||||||
|
Q_ASSERT(loc.isValid());
|
||||||
|
|
||||||
int targetPosition1 = changes->positionInFile(m_targetFileName, loc.line() - 1, loc.column() - 1);
|
int targetPosition1 = changes->positionInFile(m_targetFileName, loc.line(), loc.column());
|
||||||
int targetPosition2 = changes->positionInFile(m_targetFileName, loc.line(), 0) - 1;
|
int targetPosition2 = qMax(0, changes->positionInFile(m_targetFileName, loc.line(), 1) - 1);
|
||||||
|
|
||||||
Utils::ChangeSet target;
|
Utils::ChangeSet target;
|
||||||
target.insert(targetPosition1, loc.prefix() + m_decl);
|
target.insert(targetPosition1, loc.prefix() + m_decl);
|
||||||
@@ -104,7 +105,7 @@ public:
|
|||||||
changes->reindent(m_targetFileName,
|
changes->reindent(m_targetFileName,
|
||||||
Utils::ChangeSet::Range(targetPosition1, targetPosition2));
|
Utils::ChangeSet::Range(targetPosition1, targetPosition2));
|
||||||
|
|
||||||
changes->openEditor(m_targetFileName, loc.line() - 1, loc.column() - 1);
|
changes->openEditor(m_targetFileName, loc.line(), loc.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -158,17 +158,20 @@ QStringList RefactoringChanges::apply()
|
|||||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||||
BaseTextEditor *editor = editorForFile(m_fileNameToShow);
|
BaseTextEditor *editor = editorForFile(m_fileNameToShow);
|
||||||
editorManager->activateEditor(editor->editableInterface());
|
editorManager->activateEditor(editor->editableInterface());
|
||||||
if (m_lineToShow != -1)
|
if (m_lineToShow != 0) {
|
||||||
editor->gotoLine(m_lineToShow + 1, m_columnToShow);
|
editor->gotoLine(m_lineToShow, qMax(0, int(m_columnToShow) - 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed.toList();
|
return changed.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RefactoringChanges::positionInFile(const QString &fileName, int line, int column) const
|
int RefactoringChanges::positionInFile(const QString &fileName, unsigned line, unsigned column) const
|
||||||
{
|
{
|
||||||
if (BaseTextEditor *editor = editorForFile(fileName, true)) {
|
if (BaseTextEditor *editor = editorForFile(fileName, true)) {
|
||||||
return editor->document()->findBlockByNumber(line).position() + column;
|
Q_ASSERT(line != 0);
|
||||||
|
Q_ASSERT(column != 0);
|
||||||
|
return editor->document()->findBlockByNumber(line - 1).position() + column - 1;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -205,12 +208,7 @@ BaseTextEditor *RefactoringChanges::editorForNewFile(const QString &fileName)
|
|||||||
return editorForFile(fileName, true);
|
return editorForFile(fileName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void RefactoringChanges::openEditor(const QString &fileName, unsigned line, unsigned column)
|
||||||
* \param fileName the file to open
|
|
||||||
* \param line the line to focus on, 0-based
|
|
||||||
* \param column the column to focus on, 0-based
|
|
||||||
*/
|
|
||||||
void RefactoringChanges::openEditor(const QString &fileName, int line, int column)
|
|
||||||
{
|
{
|
||||||
m_fileNameToShow = fileName;
|
m_fileNameToShow = fileName;
|
||||||
m_lineToShow = line;
|
m_lineToShow = line;
|
||||||
|
|||||||
@@ -67,22 +67,27 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual QStringList apply();
|
virtual QStringList apply();
|
||||||
|
|
||||||
int positionInFile(const QString &fileName, int line, int column = 0) const;
|
// 1-based
|
||||||
|
int positionInFile(const QString &fileName, unsigned line, unsigned column) const;
|
||||||
|
|
||||||
static BaseTextEditor *editorForFile(const QString &fileName,
|
static BaseTextEditor *editorForFile(const QString &fileName,
|
||||||
bool openIfClosed = false);
|
bool openIfClosed = false);
|
||||||
static BaseTextEditor *editorForNewFile(const QString &fileName);
|
static BaseTextEditor *editorForNewFile(const QString &fileName);
|
||||||
|
|
||||||
/** line and column are zero-based */
|
/**
|
||||||
void openEditor(const QString &fileName, int line, int column);
|
* \param fileName the file to open
|
||||||
|
* \param line the line to focus on, 1-based
|
||||||
|
* \param column the column to focus on, 1-based
|
||||||
|
*/
|
||||||
|
void openEditor(const QString &fileName, unsigned line, unsigned column);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, QString> m_contentsByCreatedFile;
|
QMap<QString, QString> m_contentsByCreatedFile;
|
||||||
QMap<QString, Utils::ChangeSet> m_changesByFile;
|
QMap<QString, Utils::ChangeSet> m_changesByFile;
|
||||||
QMap<QString, QList<Range> > m_indentRangesByFile;
|
QMap<QString, QList<Range> > m_indentRangesByFile;
|
||||||
QString m_fileNameToShow;
|
QString m_fileNameToShow;
|
||||||
int m_lineToShow;
|
unsigned m_lineToShow;
|
||||||
int m_columnToShow;
|
unsigned m_columnToShow;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
Reference in New Issue
Block a user