Skip to content

Commit

Permalink
Reduce interaction with JCEF scrolling in the editor (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Nov 25, 2022
1 parent 8bfd335 commit a44af5f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document provides a high-level view of the changes introduced by release.
=== 0.37.57

- Fixing already disposed preview if devtools have been closed before
- Reduce interaction with JCEF scrolling in the editor (#1226)

=== 0.37.56

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ private void setupPanel() {
final AsciiDocApplicationSettings settings = AsciiDocApplicationSettings.getInstance();
myPanel = detachOldPanelAndCreateAndAttachNewOne(document, tempImagesPath, myHtmlPanelWrapper, null, retrievePanelProvider(settings));
myPanel.setEditor(editor);
myPanel.scrollToLine(targetLineNo, document.getLineCount());
forceRenderCycle();
renderIfVisible();
}
Expand Down Expand Up @@ -650,7 +649,20 @@ public void dispose() {

void scrollToLine(int line) {
targetLineNo = line;
renderIfVisible();
boolean executed = false;
synchronized (lazyExecutor) {
if (lazyExecutor.isIdle()) {
lazyExecutor.execute(() -> {
if (myPanel != null) {
myPanel.scrollToLine(line, document.getLineCount());
}
});
executed = true;
}
}
if (!executed) {
renderIfVisible();
}
}

private class MyUpdatePanelOnSettingsChangedListener implements AsciiDocApplicationSettings.SettingsChangedListener {
Expand All @@ -673,7 +685,6 @@ public void onSettingsChange(@NotNull AsciiDocApplicationSettings settings) {
if (!mySwingAlarm.isDisposed()) {
synchronized (this) {
myPanel = detachOldPanelAndCreateAndAttachNewOne(document, tempImagesPath, myHtmlPanelWrapper, myPanel, newPanelProvider);
myPanel.scrollToLine(targetLineNo, document.getLineCount());
forceRenderCycle(); // force a refresh of the preview by resetting the current memorized content
}
renderIfVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ public synchronized void execute(@NotNull final Runnable command) {
}
}
};
if (myPooledAlarm.getActiveRequestCount() == 0 && (future == null || future.isDone())) {
if (isIdle()) {
scheduleNext();
}
}

public boolean isIdle() {
return myPooledAlarm.getActiveRequestCount() == 0 && (future == null || future.isDone());
}

private synchronized void scheduleNext() {
final Runnable toSchedule = next;
next = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,10 @@ private boolean isDarcula() {


@Override
public void scrollToLine(int line, int lineCount) {
public synchronized void scrollToLine(int line, int lineCount) {
if (this.lineCount == lineCount && this.line == line) {
return;
}
this.lineCount = lineCount;
this.line = line;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ window.__IntelliJTools.scrollToLine = (function () {
(resultY < document.documentElement.scrollTop) || // position above window
(resultY > document.documentElement.scrollTop + window.height) // position below window
) {
document.documentElement.scrollTop = document.body.scrollTop = newValue;
window.scrollTo({ top: newValue, left: 0, behavior: "auto" });
}

oldLineToScroll = newLineToScroll;
Expand Down

0 comments on commit a44af5f

Please sign in to comment.