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);
|
||||
InsertionPointLocator locator(targetDoc);
|
||||
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 targetPosition2 = changes->positionInFile(m_targetFileName, loc.line(), 0) - 1;
|
||||
int targetPosition1 = changes->positionInFile(m_targetFileName, loc.line(), loc.column());
|
||||
int targetPosition2 = qMax(0, changes->positionInFile(m_targetFileName, loc.line(), 1) - 1);
|
||||
|
||||
Utils::ChangeSet target;
|
||||
target.insert(targetPosition1, loc.prefix() + m_decl);
|
||||
@@ -104,7 +105,7 @@ public:
|
||||
changes->reindent(m_targetFileName,
|
||||
Utils::ChangeSet::Range(targetPosition1, targetPosition2));
|
||||
|
||||
changes->openEditor(m_targetFileName, loc.line() - 1, loc.column() - 1);
|
||||
changes->openEditor(m_targetFileName, loc.line(), loc.column());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -158,17 +158,20 @@ QStringList RefactoringChanges::apply()
|
||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||
BaseTextEditor *editor = editorForFile(m_fileNameToShow);
|
||||
editorManager->activateEditor(editor->editableInterface());
|
||||
if (m_lineToShow != -1)
|
||||
editor->gotoLine(m_lineToShow + 1, m_columnToShow);
|
||||
if (m_lineToShow != 0) {
|
||||
editor->gotoLine(m_lineToShow, qMax(0, int(m_columnToShow) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
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 {
|
||||
return -1;
|
||||
}
|
||||
@@ -205,12 +208,7 @@ BaseTextEditor *RefactoringChanges::editorForNewFile(const QString &fileName)
|
||||
return editorForFile(fileName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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)
|
||||
void RefactoringChanges::openEditor(const QString &fileName, unsigned line, unsigned column)
|
||||
{
|
||||
m_fileNameToShow = fileName;
|
||||
m_lineToShow = line;
|
||||
|
||||
@@ -67,22 +67,27 @@ public:
|
||||
*/
|
||||
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,
|
||||
bool openIfClosed = false);
|
||||
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:
|
||||
QMap<QString, QString> m_contentsByCreatedFile;
|
||||
QMap<QString, Utils::ChangeSet> m_changesByFile;
|
||||
QMap<QString, QList<Range> > m_indentRangesByFile;
|
||||
QString m_fileNameToShow;
|
||||
int m_lineToShow;
|
||||
int m_columnToShow;
|
||||
unsigned m_lineToShow;
|
||||
unsigned m_columnToShow;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
Reference in New Issue
Block a user