Avoid joining lines for shared transcript (#1166)

This commit is contained in:
Fredrik Fornwall 2019-08-04 19:42:36 +02:00
parent 7041f41981
commit 370ac2bd89
2 changed files with 11 additions and 2 deletions

View File

@ -722,7 +722,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
if (session != null) { if (session != null) {
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain"); intent.setType("text/plain");
String transcriptText = session.getEmulator().getScreen().getTranscriptText().trim(); String transcriptText = session.getEmulator().getScreen().getTranscriptTextWithoutJoinedLines().trim();
// See https://github.com/termux/termux-app/issues/1166. // See https://github.com/termux/termux-app/issues/1166.
final int MAX_LENGTH = 100_000; final int MAX_LENGTH = 100_000;
if (transcriptText.length() > MAX_LENGTH) { if (transcriptText.length() > MAX_LENGTH) {

View File

@ -41,7 +41,15 @@ public final class TerminalBuffer {
return getSelectedText(0, -getActiveTranscriptRows(), mColumns, mScreenRows).trim(); return getSelectedText(0, -getActiveTranscriptRows(), mColumns, mScreenRows).trim();
} }
public String getTranscriptTextWithoutJoinedLines() {
return getSelectedText(0, -getActiveTranscriptRows(), mColumns, mScreenRows, false).trim();
}
public String getSelectedText(int selX1, int selY1, int selX2, int selY2) { public String getSelectedText(int selX1, int selY1, int selX2, int selY2) {
return getSelectedText(selX1, selY1, selX2, selY2, true);
}
public String getSelectedText(int selX1, int selY1, int selX2, int selY2, boolean joinBackLines) {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
final int columns = mColumns; final int columns = mColumns;
@ -79,7 +87,8 @@ public final class TerminalBuffer {
} }
if (lastPrintingCharIndex != -1) if (lastPrintingCharIndex != -1)
builder.append(line, x1Index, lastPrintingCharIndex - x1Index + 1); builder.append(line, x1Index, lastPrintingCharIndex - x1Index + 1);
if (!rowLineWrap && row < selY2 && row < mScreenRows - 1) builder.append('\n'); if ((!joinBackLines || !rowLineWrap)
&& row < selY2 && row < mScreenRows - 1) builder.append('\n');
} }
return builder.toString(); return builder.toString();
} }