Position of error marks is adjusted for selection.

Close: #20
This commit is contained in:
eelke 2018-11-10 10:59:52 +01:00
parent b0718258c9
commit f629e48a85
5 changed files with 21 additions and 13 deletions

View file

@ -4,7 +4,6 @@
#include "SqlSyntaxHighlighter.h"
#include <QStandardPaths>
#include <QPushButton>
#include <QAction>
#include <QFileDialog>
#include <QStatusBar>
@ -529,10 +528,20 @@ void QueryTab::query_ready(Expected<std::shared_ptr<Pgsql::Result>> exp_res, qin
void QueryTab::markError(const Pgsql::ErrorDetails &details)
{
if (details.statementPosition > 0) {
QTextCursor cursor = ui->queryEdit->textCursor();
cursor.setPosition(details.statementPosition-1);
// Following finds out the start of the current selection
// theoreticallly the selection might have changed however
// theoretically all the text might have changed also so we ignore
// both issues for know and we solve both when we decide it is to much of
// a problem but in practice syntax errors come back very quickly...
int position_offset = 0;
if (cursor.hasSelection()) {
position_offset = cursor.selectionStart();
}
cursor.setPosition(details.statementPosition - 1 + position_offset);
ui->queryEdit->setTextCursor(cursor);
int length = 0;
@ -554,7 +563,7 @@ void QueryTab::markError(const Pgsql::ErrorDetails &details)
}
}
}
ui->queryEdit->addErrorMarker(details.statementPosition-1, length);
ui->queryEdit->addErrorMarker(details.statementPosition - 1 + position_offset, length);
}
}