From 319e407204eb0f5cd61adef3708821f5314ad897 Mon Sep 17 00:00:00 2001 From: Ryan Hansberry Date: Tue, 13 Oct 2015 11:11:12 -0700 Subject: Make text selection scroll up when a new line enters the buffer. --- app/src/main/java/org/connectbot/TerminalView.java | 9 ++++++ .../connectbot/util/TerminalTextViewOverlay.java | 33 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/org') diff --git a/app/src/main/java/org/connectbot/TerminalView.java b/app/src/main/java/org/connectbot/TerminalView.java index 578dcd7..aec3bc5 100644 --- a/app/src/main/java/org/connectbot/TerminalView.java +++ b/app/src/main/java/org/connectbot/TerminalView.java @@ -557,6 +557,15 @@ public class TerminalView extends View implements FontSizeChangedListener { postDelayed(mEventSender, ACCESSIBILITY_EVENT_THRESHOLD); } } + + ((Activity) context).runOnUiThread(new Runnable() { + @Override + public void run() { + if (terminalTextViewOverlay != null) { + terminalTextViewOverlay.onBufferChanged(); + } + } + }); } private class AccessibilityEventSender implements Runnable { diff --git a/app/src/main/java/org/connectbot/util/TerminalTextViewOverlay.java b/app/src/main/java/org/connectbot/util/TerminalTextViewOverlay.java index b64351b..d814f7f 100644 --- a/app/src/main/java/org/connectbot/util/TerminalTextViewOverlay.java +++ b/app/src/main/java/org/connectbot/util/TerminalTextViewOverlay.java @@ -55,6 +55,7 @@ public class TerminalTextViewOverlay extends TextView { private ActionMode selectionActionMode; private ClipboardManager clipboard; + private int oldBufferHeight = 0; private int oldScrollY = -1; public TerminalTextViewOverlay(Context context) { @@ -82,16 +83,15 @@ public class TerminalTextViewOverlay extends TextView { clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); } - // TODO: optimize: instead of always copying the entire buffer, instead append() as needed. public void refreshTextFromBuffer() { VDUBuffer vb = parent.bridge.getVDUBuffer(); + int numRows = vb.getBufferSize(); + int numCols = vb.getColumns() - 1; + oldBufferHeight = numRows; String line = ""; String buffer = ""; - int numRows = vb.getBufferSize(); - int numCols = vb.getColumns() - 1; - for (int r = 0; r < numRows && vb.charArray[r] != null; r++) { for (int c = 0; c < numCols; c++) { line += vb.charArray[r][c]; @@ -105,6 +105,31 @@ public class TerminalTextViewOverlay extends TextView { setText(buffer); } + /** + * If there is a new line in the buffer, add an empty line + * in this TextView, so that selection seems to move up with the + * rest of the buffer. + */ + public void onBufferChanged() { + VDUBuffer vb = parent.bridge.getVDUBuffer(); + int numRows = vb.getBufferSize(); + int numNewRows = numRows - oldBufferHeight; + + if (numNewRows <= 0) { + return; + } + + String newLines = ""; + for (int i = 0; i < numNewRows; i++) { + newLines += "\n"; + } + + oldScrollY = (vb.getWindowBase() + numNewRows) * getLineHeight(); + oldBufferHeight = numRows; + + append(newLines); + } + @Override public boolean onPreDraw() { boolean superResult = super.onPreDraw(); -- cgit v1.2.3