* @brief Swaps the highlighter and, when recognised, the template variant. */
| 391 | * @brief Swaps the highlighter and, when recognised, the template variant. |
| 392 | */ |
| 393 | void MQTT::PublisherScriptEditor::onLanguageChanged(int index) |
| 394 | { |
| 395 | const int newLang = (index == 1) ? SerialStudio::Lua : SerialStudio::JavaScript; |
| 396 | if (newLang == m_language) |
| 397 | return; |
| 398 | |
| 399 | const int tmplIdx = detectTemplate(); |
| 400 | |
| 401 | applyLanguage(newLang); |
| 402 | |
| 403 | if (tmplIdx >= 0) { |
| 404 | const auto& tmpl = m_templates[tmplIdx]; |
| 405 | const QString code = (newLang == SerialStudio::Lua) ? tmpl.luaCode : tmpl.jsCode; |
| 406 | m_editor->setPlainText(code); |
| 407 | m_templateCombo->setCurrentIndex(tmplIdx + 1); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | const QString trimmed = m_editor->toPlainText().trimmed(); |
| 412 | const int other = (newLang == SerialStudio::Lua) ? SerialStudio::JavaScript : SerialStudio::Lua; |
| 413 | if (trimmed == defaultPlaceholder(other).trimmed()) |
| 414 | m_editor->setPlainText(defaultPlaceholder(newLang)); |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * @brief Toggles hex-mode framing of the test input. |
nothing calls this directly
no test coverage detected