Skip to content

Commit

Permalink
Moving TextSelectionManager to the document instance, so it can be sh…
Browse files Browse the repository at this point in the history
…ared by all active TextNavigator instances - otherwise one is changing and the other has a dirty cached next instance, which will never be found -> loop
  • Loading branch information
svanteschubert committed Jul 11, 2023
1 parent ece836f commit f93eff2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions odfdom/src/main/java/org/odftoolkit/odfdom/doc/OdfDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeStyles;
import org.odftoolkit.odfdom.incubator.doc.style.OdfDefaultStyle;
import org.odftoolkit.odfdom.incubator.meta.OdfOfficeMeta;
import org.odftoolkit.odfdom.incubator.search.SelectionManager;
import org.odftoolkit.odfdom.pkg.MediaType;
import org.odftoolkit.odfdom.pkg.OdfElement;
import org.odftoolkit.odfdom.pkg.OdfName;
Expand Down Expand Up @@ -1249,4 +1250,14 @@ protected void removeCachedView() {
public Boolean hasCollaboration() {
return mHasCollaboration != null && mHasCollaboration;
}

private SelectionManager mSelectionManager = null;
/** * All text selections within this document are cached and have to be updated when the document is changed.The <code>SelectionManager</code> takes care of those updates across each <code>TextNavigator</code>
* @return the single selection manager for an OdfDocument instance */
public SelectionManager getSelectionManager(){
if(mSelectionManager == null){
mSelectionManager = new SelectionManager();
}
return mSelectionManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public TextNavigation(Pattern pattern, OdfTextDocument doc) {
mCurrentSelectedItem = null;
mbFinishFindInHeaderFooter = false;

mSelectionManager = new SelectionManager();
mSelectionManager = doc.getSelectionManager();
// initialize the Iterator and find the first element...
mNextSelectedItem = findNextSelection(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TextStyleNavigation(Map<OdfStyleProperty, String> props, OdfTextDocument
mCurrentSelectedItem = null;
this.mProps = props;

mSelectionManager = new SelectionManager();
mSelectionManager = doc.getSelectionManager();
// initialize the Iterator and find the first element...
mNextSelectedItem = findNextSelection(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public void testPasteAtEndOf() {
} catch (InvalidNavigationException e) {
Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
}
}
int j = 0;
TextNavigation search4deletechange = new TextNavigation("deletechange", doc);
Expand All @@ -252,7 +253,7 @@ public void testPasteAtEndOf() {
Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
}
}
}

/**
* Test applyStyle method of org.odftoolkit.odfdom.incubator.search.TextSelection append "T4"
Expand Down

0 comments on commit f93eff2

Please sign in to comment.