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

MultiChangeBuilder should not throw new IllegalStateException("Cannot commit multiple changes since none have been added"); when empty #1083

Closed
effad opened this issue Feb 3, 2022 · 1 comment · Fixed by #1084

Comments

@effad
Copy link

effad commented Feb 3, 2022

Desired Feature

When building a multi change with MultiChangeBuilder it may often occur that no actual changes will be registered (e.g. replace all function with no matching search results).
Either the MultiChangeBuilder should just ignore (i.e. noop) in such a case or at least provide API to allow it's caller to see if there are changes to commit.

Current Workarounds

At the moment one has to clumsily note if there are actual changes in the MultiChangeBuilder, e.g. like this:

	private void replaceAll(ActionEvent e) {
		boolean hasChanges = false;
		MultiChangeBuilder<?, String, ?> multiChange = area.createMultiChange();		
		IndexRange range = getSearchFunction().search(area.getSelectedText(), search.getText(), 0);
		while (range != NOT_FOUND) {			
			multiChange.replaceText(range.getStart(), range.getEnd(), getReplacement(area.getText(range)));
			hasChanges = true;
			range = getSearchFunction().search(area.getSelectedText(), search.getText(), range.getEnd());
		}
		if (hasChanges) {
			multiChange.commit();
		}
	}
@Jugen
Copy link
Collaborator

Jugen commented Feb 3, 2022

I have no idea what the thinking is behind MultiChangeBuilder throwing IllegalStateException and it not rather being a noop as suggested. So I've submitted a PR adding a hasChanges() method, which will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants