diff options
author | Ryan Hansberry <rhansby@gmail.com> | 2015-10-13 11:11:12 -0700 |
---|---|---|
committer | Ryan Hansberry <rhansby@gmail.com> | 2015-10-14 15:47:14 -0700 |
commit | 319e407204eb0f5cd61adef3708821f5314ad897 (patch) | |
tree | fc0702d839b0ffbe6a2ad11a55301b16fb07f2ed /app/src/main/java/org | |
parent | 381c4b65027c62fa87db6038fe6de5f4e46fe990 (diff) | |
download | connectbot-319e407204eb0f5cd61adef3708821f5314ad897.tar.gz connectbot-319e407204eb0f5cd61adef3708821f5314ad897.tar.bz2 connectbot-319e407204eb0f5cd61adef3708821f5314ad897.zip |
Make text selection scroll up when a new line enters the buffer.
Diffstat (limited to 'app/src/main/java/org')
-rw-r--r-- | app/src/main/java/org/connectbot/TerminalView.java | 9 | ||||
-rw-r--r-- | app/src/main/java/org/connectbot/util/TerminalTextViewOverlay.java | 33 |
2 files changed, 38 insertions, 4 deletions
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(); |