* @brief Reformats the entire transmit-function source. */
| 231 | * @brief Reformats the entire transmit-function source. |
| 232 | */ |
| 233 | void DataModel::OutputCodeEditor::formatDocument() |
| 234 | { |
| 235 | const QString original = m_widget.toPlainText(); |
| 236 | const QString formatted = |
| 237 | CodeFormatter::formatDocument(original, CodeFormatter::Language::JavaScript); |
| 238 | if (formatted == original) |
| 239 | return; |
| 240 | |
| 241 | QTextCursor cursor = m_widget.textCursor(); |
| 242 | const int savedPos = cursor.position(); |
| 243 | cursor.beginEditBlock(); |
| 244 | cursor.select(QTextCursor::Document); |
| 245 | cursor.insertText(formatted); |
| 246 | cursor.endEditBlock(); |
| 247 | |
| 248 | cursor.setPosition(qMin(savedPos, formatted.size())); |
| 249 | m_widget.setTextCursor(cursor); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * @brief Reformats the selected lines, or the current line when nothing is selected. |
nothing calls this directly
no test coverage detected