Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public class Edition{
private final File file;
private final File editFile;
private static final BooleanProperty isSave = new SimpleBooleanProperty(true);


// Stores the scroll value loaded from the edit file (used to restore scroll position)
private double loadedScrollValue = 0;

public Document document;

public Edition(File file, Document document){
Expand All @@ -68,7 +71,10 @@ public boolean load(boolean updateScrollValue){
boolean upscaleGrid = versionID == 0; // Between 1.2.1 and 1.3.0, the grid size was multiplied by 100

Double lastScrollValue = config.getDoubleNull("lastScrollValue");
if(lastScrollValue != null && updateScrollValue) document.setCurrentScrollValue(lastScrollValue);
if(lastScrollValue != null){
loadedScrollValue = lastScrollValue;
if(updateScrollValue) document.setCurrentScrollValue(lastScrollValue);
}

loadItemsInPage(config.getSection("vectors").entrySet(), elementData -> {
VectorElement.readYAMLDataAndCreate(elementData.getValue(), elementData.getKey());
Expand Down Expand Up @@ -179,15 +185,17 @@ public void saveLastScrollValue(){
try{
Config config = new Config(editFile);
config.load();

config.base.put("lastScrollValue", document.getLastScrollValue());

config.save();
}catch(Exception e){
Log.eNotified(e);
}
}


public double getLoadedScrollValue(){
return loadedScrollValue;
}

private ArrayList<Object> getPageDataFromElements(ArrayList<Element> elements, Class<? extends Element> acceptedElements){
ArrayList<Object> pageData = elements.stream()
.filter(acceptedElements::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,22 @@ public void openFile(File file, boolean resetScrollValue){

repaint();
isRotating = false; // Can sometimes be kept to true


// Get the scroll value loaded from the edition file (not from scrollbar which may be unreliable)
double scrollValue = document.edition.getLoadedScrollValue();

// Zoom #2. If had opened file, keep same zoom factor.
if(!hadOpenedFile){
if(MainWindow.userData.editPagesMode) zoomOperator.overviewWidth(true);
else zoomOperator.fitWidth(true, false);
}else zoomOperator.zoom(oldPaneScale, true);

// Scroll position
if(MainWindow.userData.editPagesMode){
PlatformUtils.runLaterOnUIThread(500, () -> zoomOperator.updatePaneDimensions(0, 0.5));
}else{
double scrollValue = zoomOperator.vScrollBar.getValue(); // This value has been set when loading the edition
zoomOperator.updatePaneDimensions(scrollValue, 0.5);
final double finalScrollValue = scrollValue;
Platform.runLater(() -> zoomOperator.vScrollBar.setValue(finalScrollValue));
}

// Update menu bar
Expand Down