| 2397 | } |
| 2398 | |
| 2399 | void RcxEditor::setCommandRowText(const QString& line) { |
| 2400 | if (m_sci->lines() <= 0) return; |
| 2401 | QString s = line; |
| 2402 | s.replace('\n', ' '); |
| 2403 | s.replace('\r', ' '); |
| 2404 | |
| 2405 | bool wasReadOnly = m_sci->isReadOnly(); |
| 2406 | bool wasModified = m_sci->SendScintilla(QsciScintillaBase::SCI_GETMODIFY); |
| 2407 | long savedPos = m_sci->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS); |
| 2408 | long savedAnchor = m_sci->SendScintilla(QsciScintillaBase::SCI_GETANCHOR); |
| 2409 | |
| 2410 | m_sci->SendScintilla(QsciScintillaBase::SCI_SETUNDOCOLLECTION, 0); |
| 2411 | m_sci->setReadOnly(false); |
| 2412 | |
| 2413 | long start = m_sci->SendScintilla(QsciScintillaBase::SCI_POSITIONFROMLINE, 0); |
| 2414 | long end = m_sci->SendScintilla(QsciScintillaBase::SCI_GETLINEENDPOSITION, 0); |
| 2415 | QByteArray utf8 = s.toUtf8(); |
| 2416 | long oldLen = end - start; |
| 2417 | m_sci->SendScintilla(QsciScintillaBase::SCI_SETTARGETSTART, start); |
| 2418 | m_sci->SendScintilla(QsciScintillaBase::SCI_SETTARGETEND, end); |
| 2419 | m_sci->SendScintilla(QsciScintillaBase::SCI_REPLACETARGET, (uintptr_t)utf8.size(), utf8.constData()); |
| 2420 | |
| 2421 | // Adjust saved cursor/anchor for length change in line 0 |
| 2422 | long delta = (long)utf8.size() - oldLen; |
| 2423 | if (savedPos > end) savedPos += delta; |
| 2424 | if (savedAnchor > end) savedAnchor += delta; |
| 2425 | |
| 2426 | if (wasReadOnly) m_sci->setReadOnly(true); |
| 2427 | m_sci->SendScintilla(QsciScintillaBase::SCI_SETUNDOCOLLECTION, 1); |
| 2428 | if (!wasModified) m_sci->SendScintilla(QsciScintillaBase::SCI_SETSAVEPOINT); |
| 2429 | m_sci->SendScintilla(QsciScintillaBase::SCI_SETCURRENTPOS, savedPos); |
| 2430 | m_sci->SendScintilla(QsciScintillaBase::SCI_SETANCHOR, savedAnchor); |
| 2431 | m_sci->SendScintilla(QsciScintillaBase::SCI_COLOURISE, start, start + utf8.size()); |
| 2432 | applyCommandRowPills(); |
| 2433 | } |
| 2434 | |
| 2435 | void RcxEditor::setEditorFont(const QString& fontName) { |
| 2436 | g_fontName = fontName; |