Skip to content

Commit

Permalink
Improve scroll, do not scroll out of bound
Browse files Browse the repository at this point in the history
  • Loading branch information
tranleduy2000 committed May 29, 2018
1 parent 837c1fa commit bd2c4a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package com.duy.ccppcompiler.compiler.compilers;

import android.content.Context;
import android.support.annotation.NonNull;

import com.duy.ccppcompiler.compiler.shell.CommandResult;

import java.io.File;

Expand All @@ -41,4 +44,10 @@ protected String buildArgs(File[] sourceFiles) {
protected String getCompilerProgram() {
return MARK_PROGRAM;
}

@NonNull
@Override
protected CommandResult execCommand(@NonNull Context context, @NonNull String workingDir, @NonNull String cmd) {
return super.execCommand(context, workingDir, cmd);
}
}
13 changes: 12 additions & 1 deletion editor/src/main/java/android/core/widget/EditAreaView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

import android.content.Context;
import android.core.content.UndoManager;
import android.core.text.Layout;
import android.core.text.Selection;
import android.core.text.method.ArrowKeyMovementMethod;
import android.core.text.method.MovementMethod;
import android.core.view.InputMethodManagerCompat;
import android.core.widget.model.EditorIndex;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputFilter;
Expand Down Expand Up @@ -370,7 +372,16 @@ public int realLineToVirtualLine(int realLine) {
*/
public void scrollToLine(int virtualLine) {
virtualLine = Math.max(0, Math.min(virtualLine, getLineCount() - 1));
int y = getLayout().getLineTop(virtualLine);
final Layout layout = getLayout();
final int layoutHeight = layout.getHeight();


Rect bound = new Rect();
getGlobalVisibleRect(bound);
final int visibleHeight = bound.height();

int y = layout.getLineTop(virtualLine);
y = Math.min(y, layoutHeight - visibleHeight);
scrollTo(getScrollX(), y);
}

Expand Down

0 comments on commit bd2c4a9

Please sign in to comment.