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

Method onFormat

app/src/DataModel/Editors/DatasetTransformEditor.cpp:350–368  ·  view source on GitHub ↗

* @brief Reformats the entire transform script. */

Source from the content-addressed store, hash-verified

348 * @brief Reformats the entire transform script.
349 */
350void DataModel::DatasetTransformEditor::onFormat()
351{
352 const auto lang = (m_language == SerialStudio::Lua) ? CodeFormatter::Language::Lua
353 : CodeFormatter::Language::JavaScript;
354 const QString original = m_editor->toPlainText();
355 const QString formatted = CodeFormatter::formatDocument(original, lang);
356 if (formatted == original)
357 return;
358
359 QTextCursor cursor = m_editor->textCursor();
360 const int savedPos = cursor.position();
361 cursor.beginEditBlock();
362 cursor.select(QTextCursor::Document);
363 cursor.insertText(formatted);
364 cursor.endEditBlock();
365
366 cursor.setPosition(qMin(savedPos, formatted.size()));
367 m_editor->setTextCursor(cursor);
368}
369
370/**
371 * @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