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

Method copy

app/src/UI/Widgets/Terminal.cpp:928–963  ·  view source on GitHub ↗

* @brief Copies the currently selected text to the system clipboard. */

Source from the content-addressed store, hash-verified

926 * @brief Copies the currently selected text to the system clipboard.
927 */
928void Widgets::Terminal::copy()
929{
930 if (!copyAvailable())
931 return;
932
933 QString copiedText;
934 QPoint start = m_selectionStart;
935 QPoint end = m_selectionEnd;
936
937 if (start.y() > end.y() || (start.y() == end.y() && start.x() > end.x()))
938 std::swap(start, end);
939
940 for (int lineIndex = start.y(); lineIndex <= end.y(); ++lineIndex) {
941 const QString& line = m_data[lineIndex];
942
943 int startX = (lineIndex == start.y()) ? start.x() : 0;
944 int endX = (lineIndex == end.y()) ? end.x() : line.size();
945
946 if (start.y() == end.y() && start.x() > end.x())
947 std::swap(startX, endX);
948
949 if (lineIndex != start.y() && lineIndex != end.y()) {
950 startX = 0;
951 endX = line.size();
952 }
953
954 if (startX < endX)
955 copiedText.append(line.mid(startX, endX - startX));
956
957 if (lineIndex != end.y() || (startX == 0 && endX == line.size()))
958 copiedText.append('\n');
959 }
960
961 QClipboard* clipboard = QGuiApplication::clipboard();
962 clipboard->setText(copiedText);
963}
964
965/**
966 * @brief Clears the terminal's content.

Callers 4

renderFallbackTileMethod · 0.45
renderCloudOverlayMethod · 0.45
process_readingsFunction · 0.45
_get_satellite_patchFunction · 0.45

Calls 3

xMethod · 0.80
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected