MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / createCodeEdit

Method createCodeEdit

src/plugins/chat/widgets/messagecomponent.cpp:276–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276bool MessageComponent::createCodeEdit(const MessageData &newData)
277{
278 QStringList newLines = newData.messageLines();
279 QStringList oldLines = messageData.messageLines();
280 QStringList addedLines = newLines.mid(oldLines.count());
281
282 for (int i = 0; i < addedLines.count(); ++i) {
283 QString addedLine = addedLines.at(i).trimmed();
284 if (addedLine.contains("`") || addedLine.isEmpty()) {
285 if (i != 0) {
286 MessageData addedMsgData = messageData;
287 addedMsgData.appendData(addedLines.mid(0, i));
288 updateMessage(addedMsgData);
289 }
290
291 QRegExp re("```([a-z]*|[A-Z]*)");
292 if (re.exactMatch(addedLine) && currentUpdateState == Label) {
293 // create new code edit component
294 messageData.appendData({ addedLine });
295 currentUpdateState = CodeEdit;
296 curUpdateEdit = new CodeEditComponent(this);
297 curUpdateEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
298 curUpdateEdit->setReadOnly(true);
299 curUpdateEdit->setUpdateHeight(true);
300 curUpdateEdit->showButtons(CodeEditComponent::CopyAndInsert);
301 msgLayout->addWidget(curUpdateEdit);
302 return true;
303 } else if (addedLine == "```" && currentUpdateState == CodeEdit) {
304 // end the code edit component update
305 messageData.appendData({ addedLine });
306 currentUpdateState = Label;
307 curUpdateLabel = new DLabel(this);
308 curUpdateLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
309 curUpdateLabel->setWordWrap(true);
310 msgLayout->addWidget(curUpdateLabel);
311 if (i != (addedLines.count() - 1))
312 updateMessage(newData);
313
314 return false;
315 } else if (addedLine.size() > 4) { // addedline starts with ` but not ```. eg: `123`
316 return true;
317 }
318 return false;
319 }
320 }
321
322 return true;
323}
324
325void MessageComponent::showWebsitesReferences()
326{

Callers

nothing calls this directly

Calls 11

messageLinesMethod · 0.80
atMethod · 0.80
appendDataMethod · 0.80
setUpdateHeightMethod · 0.80
showButtonsMethod · 0.80
countMethod · 0.45
containsMethod · 0.45
isEmptyMethod · 0.45
setReadOnlyMethod · 0.45
addWidgetMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected