Skip to content

Commit b8df8ba

Browse files
committed
修复选区为空时高亮一整行的问题
1 parent 09361f1 commit b8df8ba

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

regex_tool/mainwindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ void MainWindow::setTextColor(QPlainTextEdit *edit, int start, int end)
151151
cursor.setPosition(start);
152152
edit->setTextCursor(cursor);
153153
edit->ensureCursorVisible();
154+
155+
// 如果开始和结束位置相同,只设置光标位置,不高亮,
156+
// 否则 Qt 会高亮一整行
157+
if (start == end)
158+
{
159+
edit->setFocus();
160+
return;
161+
}
162+
154163
cursor.setPosition(end, QTextCursor::KeepAnchor);
155164

156165
auto fmt = QTextCharFormat();
@@ -423,6 +432,7 @@ void MainWindow::onTableSelectionChanged(const QModelIndex &current, const QMode
423432
{
424433
auto point = current.data(Qt::UserRole + 1).toPoint();
425434
setTextColor(input_edit, point.x(), point.y());
435+
statusbar->showMessage(QString("(%1, %2) %3").arg(point.x()).arg(point.y()).arg(current.data().toString()));
426436
}
427437

428438
bool MainWindow::eventFilter(QObject *watched, QEvent *event)

0 commit comments

Comments
 (0)