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

Method formatDocument

app/src/DataModel/Editors/OutputCodeEditor.cpp:233–250  ·  view source on GitHub ↗

* @brief Reformats the entire transmit-function source. */

Source from the content-addressed store, hash-verified

231 * @brief Reformats the entire transmit-function source.
232 */
233void 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.

Callers

nothing calls this directly

Calls 2

formatDocumentFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected