diff --git a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/MindMapView.java b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/MindMapView.java index 3cfa4145..03cc4c88 100644 --- a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/MindMapView.java +++ b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/MindMapView.java @@ -1661,12 +1661,14 @@ public void cut() { public boolean copyTopicsToClipboard(List topics, boolean cut) { boolean result = false; this.endEdit(null, false); - if (topics.size() > 0) { + if (!topics.isEmpty()) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent clipboardContent = new ClipboardContent(); ClipboardTopicsContainer container = new ClipboardTopicsContainer(topics.toArray(new TopicNode[]{})); try { - clipboardContent.putString(ClipboardTopicsContainer.convertTopics(topics)); + String text = ClipboardTopicsContainer.convertTopics(topics); + if (log.isTraceEnabled()) log.trace("Text to clipboard: '%s'".formatted(text)); + clipboardContent.putString(text); clipboardContent.put(MMD_DATA_FORMAT, container); } catch (Exception e) { throw new RuntimeException(e); diff --git a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/clipboard/ClipboardTopicsContainer.java b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/clipboard/ClipboardTopicsContainer.java index acb5d713..9260340f 100644 --- a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/clipboard/ClipboardTopicsContainer.java +++ b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/clipboard/ClipboardTopicsContainer.java @@ -1,6 +1,9 @@ package com.mindolph.mindmap.clipboard; -import com.igormaznitsa.mindmap.model.*; +import com.igormaznitsa.mindmap.model.Extra; +import com.igormaznitsa.mindmap.model.ExtraNote; +import com.igormaznitsa.mindmap.model.ExtraTopic; +import com.igormaznitsa.mindmap.model.MindMap; import com.mindolph.mindmap.model.TopicNode; import org.apache.commons.lang3.StringUtils; @@ -18,7 +21,6 @@ public final class ClipboardTopicsContainer implements Serializable { private final TopicNode[] topics; /** - * * @param topics topics that don't have any ancestor-descendant relationship, * otherwise any operations on these topics might with redundant topics. */ @@ -35,14 +37,8 @@ private static String oneLineTitle(TopicNode topic) { } public static String convertTopics(List topics) { - StringBuilder result = new StringBuilder(); - for (TopicNode t : topics) { - if (result.length() > 0) { - result.append(LINE_SEPARATOR); - } - result.append(convertTopic(t, 0)); - } - return result.toString(); + List texts = topics.stream().map(topicNode -> convertTopic(topicNode, 0).trim()).toList(); + return StringUtils.join(texts, LINE_SEPARATOR); } private static String convertTopic(TopicNode topic, int level) { @@ -64,8 +60,7 @@ private static String convertTopic(TopicNode topic, int level) { case NOTE: { if (Boolean.parseBoolean(topic.getAttributes().get(ExtraNote.ATTR_ENCRYPTED))) { result.append(LINE_SEPARATOR).append(lineIndent).append(""); - } - else { + } else { for (String s : e.getValue().getAsString().split(LINE_SEPARATOR)) { result.append(LINE_SEPARATOR).append(lineIndent).append("> ").append(s.trim()); }