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

Synchronize scrollbars in the change resolver dialog #10587

Merged
merged 6 commits into from
Oct 28, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Changed

- The two previews in the change resolver dialog now have their scrollbars synchronized [#9576](https://github.com/JabRef/jabref/issues/9576).
- We changed the setting of the keyword separator to accept a single character only. [#177](https://github.com/koppor/jabref/issues/177)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.jabref.gui.collab.entrychange;

import javafx.event.Event;
import javafx.geometry.Orientation;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TabPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
Expand All @@ -23,6 +26,7 @@
public final class EntryChangeDetailsView extends DatabaseChangeDetailsView {
private final PreviewWithSourceTab oldPreviewWithSourcesTab = new PreviewWithSourceTab();
private final PreviewWithSourceTab newPreviewWithSourcesTab = new PreviewWithSourceTab();
private boolean scrolling = false;

public EntryChangeDetailsView(BibEntry oldEntry,
BibEntry newEntry,
Expand All @@ -42,6 +46,13 @@ public EntryChangeDetailsView(BibEntry oldEntry,
// we need a copy here as we otherwise would set the same entry twice
PreviewViewer previewClone = new PreviewViewer(databaseContext, dialogService, preferencesService, stateManager, themeManager, taskExecutor);

// The scroll bar used is not part of ScrollPane, but the attached WebView.
WebView previewCloneView = (WebView) previewClone.getContent();
WebView previewViewerView = (WebView) previewViewer.getContent();
synchronizeScrolling(previewCloneView, previewViewerView);
synchronizeScrolling(previewViewerView, previewCloneView);
// TODO: Also sync scrolling for BibTeX view.

TabPane oldEntryTabPane = oldPreviewWithSourcesTab.getPreviewWithSourceTab(oldEntry, databaseContext, preferencesService, entryTypesManager, previewClone, Localization.lang("Entry Preview"));
TabPane newEntryTabPane = newPreviewWithSourcesTab.getPreviewWithSourceTab(newEntry, databaseContext, preferencesService, entryTypesManager, previewViewer, Localization.lang("Entry Preview"));

Expand All @@ -68,4 +79,24 @@ public EntryChangeDetailsView(BibEntry oldEntry,

this.getChildren().add(split);
}

// Method adapted from:
// https://stackoverflow.com/questions/49509395/synchronize-scrollbars-of-two-javafx-webviews
// https://stackoverflow.com/questions/31264847/how-to-set-remember-scrollbar-thumb-position-in-javafx-8-webview
private void synchronizeScrolling(WebView webView, WebView otherWebView) {
webView.addEventHandler(Event.ANY, event -> {
if (!scrolling) {
scrolling = true;
if (event instanceof MouseEvent) {
if (((MouseEvent) event).isPrimaryButtonDown()) {
int value = (Integer) webView.getEngine().executeScript("window.scrollY");
otherWebView.getEngine().executeScript("window.scrollTo(0, " + value + ")");
}
} else {
otherWebView.fireEvent(event.copyFor(otherWebView, otherWebView));
}
scrolling = false;
}
});
}
}
Loading