Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[reopen] Scroll position in content #664

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions editor/src/main/java/io/github/rosemoe/sora/text/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class Content implements CharSequence {
private final ReadWriteLock lock;
private int textLength;
private int nestedBatchEdit;
private int scrollX;
private int scrollY;
private final AtomicLong documentVersion = new AtomicLong(1L);
private final Indexer indexer;
private final ContentBidi bidi;
Expand Down Expand Up @@ -98,6 +100,8 @@ public Content(CharSequence src, boolean threadSafe) {
}
textLength = 0;
nestedBatchEdit = 0;
scrollX = 0;
scrollY = 0;
lines = new ArrayList<>(getInitialLineCapacity());
lines.add(new ContentLine());
contentListeners = new ArrayList<>();
Expand Down Expand Up @@ -1003,6 +1007,34 @@ public boolean isCursorCreated() {
return cursor != null;
}

/**
* Get horizontal scroll position of editor
*/
public int getScrollX() {
return scrollX;
}

/**
* Get vertical scroll position of editor
*/
public int getScrollY() {
return scrollY;
}

/**
* Set horizontal scroll position. This does not affect the editor.
*/
public void setScrollX(int scrollX) {
this.scrollX = scrollX;
}

/**
* Set vertical scroll position. This does not affect the editor.
*/
public void setScrollY(int scrollY) {
this.scrollY = scrollY;
}

/**
* Dispatch events to listener before replacement
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4845,6 +4845,13 @@ protected void onSizeChanged(int w, int h, int oldWidth, int oldHeight) {
}
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
text.setScrollX(l);
text.setScrollY(t);
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Expand Down