| 288 | } |
| 289 | |
| 290 | void InputEdit::onTextChanged() |
| 291 | { |
| 292 | auto adjustHeight = document()->size().height(); |
| 293 | if (adjustHeight < minInputEditHeight) |
| 294 | setFixedHeight(minInputEditHeight); |
| 295 | else if (adjustHeight > maxInputEditHeight) |
| 296 | setFixedHeight(maxInputEditHeight); |
| 297 | else |
| 298 | setFixedHeight(adjustHeight); |
| 299 | |
| 300 | QTextCursor cursor(document()); |
| 301 | QSet<QString> tagList; |
| 302 | int last_pos = 0; |
| 303 | |
| 304 | // bug: tag will removed when send message. and causes the tag to be reset before it is used. |
| 305 | // update tag when llm is not running |
| 306 | if (ChatManager::instance()->checkRunningState(true)) |
| 307 | return; |
| 308 | |
| 309 | cursor.setPosition(0); |
| 310 | formatList.clear(); |
| 311 | |
| 312 | while (!cursor.atEnd()) { |
| 313 | cursor.setPosition(last_pos + 1); |
| 314 | |
| 315 | if (last_pos == cursor.position()) |
| 316 | break; |
| 317 | last_pos = cursor.position(); |
| 318 | |
| 319 | TagTextFormat format(cursor.charFormat()); |
| 320 | if (format.objectType() == QTextFormat::UserObject + 1) { |
| 321 | const QString &text = format.text(); |
| 322 | |
| 323 | if (!text.isEmpty()) { |
| 324 | tagList << text; |
| 325 | formatList << text; |
| 326 | |
| 327 | if (!formats.contains(text)) { |
| 328 | formats[text] = format; |
| 329 | Q_EMIT tagAdded(text); |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | Q_FOREACH (const TagTextFormat &f, formats) { |
| 336 | if (!tagList.contains(f.text())) { |
| 337 | formats.remove(f.text()); |
| 338 | Q_EMIT tagRemoved(f.text()); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | bool InputEdit::event(QEvent *e) |
| 344 | { |
no test coverage detected