* @brief Reformats the entire painter source. */
| 243 | * @brief Reformats the entire painter source. |
| 244 | */ |
| 245 | void DataModel::PainterCodeEditor::formatDocument() |
| 246 | { |
| 247 | const QString original = m_widget.toPlainText(); |
| 248 | const QString formatted = |
| 249 | CodeFormatter::formatDocument(original, CodeFormatter::Language::JavaScript); |
| 250 | if (formatted == original) |
| 251 | return; |
| 252 | |
| 253 | QTextCursor cursor = m_widget.textCursor(); |
| 254 | const int savedPos = cursor.position(); |
| 255 | cursor.beginEditBlock(); |
| 256 | cursor.select(QTextCursor::Document); |
| 257 | cursor.insertText(formatted); |
| 258 | cursor.endEditBlock(); |
| 259 | |
| 260 | cursor.setPosition(qMin(savedPos, formatted.size())); |
| 261 | m_widget.setTextCursor(cursor); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @brief Reformats the selected lines (or current line when nothing is selected). |
nothing calls this directly
no test coverage detected