Fix marking JavaScript lines that threw an exception

Since EditorManager::openedEditors doesn't exactly do what one would
expect, it was only marking a single editor even if there were multiple
editors on the same document.

Change-Id: Iae579c2cfd8455de2783d39fa69944fe92dfc60a
Reviewed-by: Aurindam Jana <aurindam.jana@digia.com>
This commit is contained in:
Eike Ziller
2013-07-16 13:51:44 +02:00
parent 00a46667d7
commit 746e4f4119
3 changed files with 38 additions and 36 deletions

View File

@@ -163,7 +163,7 @@ void DocumentModel::addEntry(Entry *entry)
QString fileName = entry->fileName(); QString fileName = entry->fileName();
// replace a non-loaded entry (aka 'restored') if possible // replace a non-loaded entry (aka 'restored') if possible
int previousIndex = indexofFileName(fileName); int previousIndex = indexOfFilePath(fileName);
if (previousIndex >= 0) { if (previousIndex >= 0) {
if (entry->document && d->m_documents.at(previousIndex)->document == 0) { if (entry->document && d->m_documents.at(previousIndex)->document == 0) {
Entry *previousEntry = d->m_documents.at(previousIndex); Entry *previousEntry = d->m_documents.at(previousIndex);
@@ -190,12 +190,12 @@ void DocumentModel::addEntry(Entry *entry)
endInsertRows(); endInsertRows();
} }
int DocumentModel::indexofFileName(const QString &filename) const int DocumentModel::indexOfFilePath(const QString &filePath) const
{ {
if (filename.isEmpty()) if (filePath.isEmpty())
return -1; return -1;
for (int i = 0; i < d->m_documents.count(); ++i) { for (int i = 0; i < d->m_documents.count(); ++i) {
if (d->m_documents.at(i)->fileName() == filename) if (d->m_documents.at(i)->fileName() == filePath)
return i; return i;
} }
return -1; return -1;
@@ -226,7 +226,7 @@ void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument)
void DocumentModel::removeDocument(const QString &fileName) void DocumentModel::removeDocument(const QString &fileName)
{ {
int index = indexofFileName(fileName); int index = indexOfFilePath(fileName);
QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors
removeDocument(index); removeDocument(index);
} }

View File

@@ -77,6 +77,7 @@ public:
int documentCount() const; int documentCount() const;
QList<Entry *> documents() const; QList<Entry *> documents() const;
int indexOfDocument(IDocument *document) const; int indexOfDocument(IDocument *document) const;
int indexOfFilePath(const QString &filePath) const;
Entry *entryForDocument(IDocument *document) const; Entry *entryForDocument(IDocument *document) const;
QList<IDocument *> openedDocuments() const; QList<IDocument *> openedDocuments() const;
@@ -98,7 +99,6 @@ private slots:
private: private:
void addEntry(Entry *entry); void addEntry(Entry *entry);
int indexofFileName(const QString &filename) const;
void removeDocument(int idx); void removeDocument(int idx);
DocumentModelPrivate *d; DocumentModelPrivate *d;

View File

@@ -1993,16 +1993,19 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
const QString &filePath, const QString &filePath,
const QString &errorMessage) const QString &errorMessage)
{ {
EditorManager *editorManager = EditorManager::instance(); DocumentModel *documentModel = EditorManager::documentModel();
QList<IEditor *> openedEditors = editorManager->openedEditors(); int index = documentModel->indexOfFilePath(filePath);
if (index < 0 || !documentModel->documents().at(index)->document)
return;
QList<IEditor *> editors = documentModel->editorsForDocument(
documentModel->documents().at(index)->document);
// set up the format for the errors // set up the format for the errors
QTextCharFormat errorFormat; QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
errorFormat.setUnderlineColor(Qt::red); errorFormat.setUnderlineColor(Qt::red);
foreach (IEditor *editor, openedEditors) { foreach (IEditor *editor, editors) {
if (editor->document()->filePath() == filePath) {
TextEditor::BaseTextEditorWidget *ed = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget()); TextEditor::BaseTextEditorWidget *ed = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
if (!ed) if (!ed)
continue; continue;
@@ -2030,13 +2033,12 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
.arg(errorMessage); .arg(errorMessage);
d->engine->showMessage(message, ConsoleOutput); d->engine->showMessage(message, ConsoleOutput);
} }
}
} }
void QmlV8DebuggerClient::clearExceptionSelection() void QmlV8DebuggerClient::clearExceptionSelection()
{ {
EditorManager *editorManager = EditorManager::instance(); DocumentModel *documentModel = EditorManager::documentModel();
QList<IEditor *> openedEditors = editorManager->openedEditors(); QList<IEditor *> openedEditors = documentModel->editorsForDocuments(documentModel->openedDocuments());
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
foreach (IEditor *editor, openedEditors) { foreach (IEditor *editor, openedEditors) {