MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / formatDocument

Method formatDocument

app/src/DataModel/Editors/PainterCodeEditor.cpp:245–262  ·  view source on GitHub ↗

* @brief Reformats the entire painter source. */

Source from the content-addressed store, hash-verified

243 * @brief Reformats the entire painter source.
244 */
245void 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).

Callers

nothing calls this directly

Calls 2

formatDocumentFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected