Skip to content

Commit

Permalink
fix: redundant line break at the end of copied text of topics from mi…
Browse files Browse the repository at this point in the history
…nd map.
  • Loading branch information
mindolph committed Mar 23, 2024
1 parent 83af968 commit e35a911
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1661,12 +1661,14 @@ public void cut() {
public boolean copyTopicsToClipboard(List<TopicNode> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
*/
Expand All @@ -35,14 +37,8 @@ private static String oneLineTitle(TopicNode topic) {
}

public static String convertTopics(List<TopicNode> 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<String> texts = topics.stream().map(topicNode -> convertTopic(topicNode, 0).trim()).toList();
return StringUtils.join(texts, LINE_SEPARATOR);
}

private static String convertTopic(TopicNode topic, int level) {
Expand All @@ -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("<ENCRYPTED NOTE>");
}
else {
} else {
for (String s : e.getValue().getAsString().split(LINE_SEPARATOR)) {
result.append(LINE_SEPARATOR).append(lineIndent).append("> ").append(s.trim());
}
Expand Down

0 comments on commit e35a911

Please sign in to comment.