Skip to content

Commit

Permalink
Fix scroll poses after refresh (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
pertsevpv authored Dec 2, 2024
1 parent 188fa4a commit 70f9a70
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.sudu.experiments.editor.ui.colors.EditorColorScheme;
import org.sudu.experiments.editor.worker.diff.DiffInfo;
import org.sudu.experiments.js.JsArray;
import org.sudu.experiments.math.V2i;
import org.sudu.experiments.protocol.JsCast;
import org.sudu.experiments.ui.window.WindowManager;
import org.sudu.experiments.update.FileDiffChannelUpdater;
Expand All @@ -20,6 +21,8 @@ public class RemoteFileDiffWindow extends FileDiffWindow {

private final Channel channel;
private boolean haveLeftHandle, haveRightHandle;
private int lastLeftScrollPos = -1, lastRightScrollPos = -1;
private V2i lastLeftCaretPos = null, lastRightCaretPos = null;

public RemoteFileDiffWindow(
WindowManager wm,
Expand Down Expand Up @@ -67,6 +70,7 @@ private void onFileRead(JsArray<JSObject> jsArray) {
"RemoteFileDiffWindow.open: name = " + name
+ ", encoding = " + encoding);
open(source, encoding, name, left);
updateOnRefresh();
}

private void onDiffSent(JsArray<JSObject> jsArray) {
Expand All @@ -89,11 +93,22 @@ public void onRefresh() {
rootView.unsetModelFlagsBit(1);
leftFile = null;
sendReadFile(true);
lastLeftScrollPos = rootView.editor1.getVScrollPos();
lastLeftCaretPos = rootView.editor1.model().getCaretPos();
}
if (haveRightHandle) {
rootView.unsetModelFlagsBit(2);
rightFile = null;
sendReadFile(false);
lastRightScrollPos = rootView.editor2.getVScrollPos();
lastRightCaretPos = rootView.editor2.model().getCaretPos();
}
}

private void updateOnRefresh() {
if (lastLeftCaretPos != null) rootView.editor1.setPosition(lastLeftCaretPos.y, lastLeftCaretPos.x);
if (lastRightCaretPos != null) rootView.editor2.setPosition(lastRightCaretPos.y, lastRightCaretPos.x);
if (lastLeftScrollPos != -1) rootView.editor1.setVScrollPosSilent(lastLeftScrollPos);
if (lastRightScrollPos != -1) rootView.editor2.setVScrollPosSilent(lastRightScrollPos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ public void setOnRefresh(Runnable onRefresh) {

public void refresh() {
System.out.println("FileDiffRootView.refresh");
firstDiffRevealed = false;
if (onRefresh != null) onRefresh.run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ public boolean setVScrollPosSilent(int vPos) {
return change;
}

public int getVScrollPos() {
return vScrollPos;
}

@Override
public V2i minimalSize() {
return new V2i(lineNumbersWidth() + vLineW + vLineLeftDelta, lineHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public String uriScheme() {
return uri != null ? uri.scheme : null;
}

public V2i getCaretPos() {
return new V2i(caretLine, caretCharPos);
}

void onFileParsed(Object[] result) {
// Debug.consoleInfo("onFileParsed");
fileStructureParsed = ParseStatus.PARSED;
Expand Down

0 comments on commit 70f9a70

Please sign in to comment.