Skip to content

Commit bd2c4a9

Browse files
committed
Improve scroll, do not scroll out of bound
1 parent 837c1fa commit bd2c4a9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/MakeCompiler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package com.duy.ccppcompiler.compiler.compilers;
1818

1919
import android.content.Context;
20+
import android.support.annotation.NonNull;
21+
22+
import com.duy.ccppcompiler.compiler.shell.CommandResult;
2023

2124
import java.io.File;
2225

@@ -41,4 +44,10 @@ protected String buildArgs(File[] sourceFiles) {
4144
protected String getCompilerProgram() {
4245
return MARK_PROGRAM;
4346
}
47+
48+
@NonNull
49+
@Override
50+
protected CommandResult execCommand(@NonNull Context context, @NonNull String workingDir, @NonNull String cmd) {
51+
return super.execCommand(context, workingDir, cmd);
52+
}
4453
}

editor/src/main/java/android/core/widget/EditAreaView.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
import android.content.Context;
2222
import android.core.content.UndoManager;
23+
import android.core.text.Layout;
2324
import android.core.text.Selection;
2425
import android.core.text.method.ArrowKeyMovementMethod;
2526
import android.core.text.method.MovementMethod;
2627
import android.core.view.InputMethodManagerCompat;
2728
import android.core.widget.model.EditorIndex;
2829
import android.graphics.Canvas;
30+
import android.graphics.Rect;
2931
import android.support.annotation.Nullable;
3032
import android.text.Editable;
3133
import android.text.InputFilter;
@@ -370,7 +372,16 @@ public int realLineToVirtualLine(int realLine) {
370372
*/
371373
public void scrollToLine(int virtualLine) {
372374
virtualLine = Math.max(0, Math.min(virtualLine, getLineCount() - 1));
373-
int y = getLayout().getLineTop(virtualLine);
375+
final Layout layout = getLayout();
376+
final int layoutHeight = layout.getHeight();
377+
378+
379+
Rect bound = new Rect();
380+
getGlobalVisibleRect(bound);
381+
final int visibleHeight = bound.height();
382+
383+
int y = layout.getLineTop(virtualLine);
384+
y = Math.min(y, layoutHeight - visibleHeight);
374385
scrollTo(getScrollX(), y);
375386
}
376387

0 commit comments

Comments
 (0)