Hi all!
As stated in subject, we found a potential issue in SourceCodeEditor.
Use Case:
When using SourceCodeEditor and applying a suggestion with both startPosition and endPosition greater than -1, the endPosition parameter seems to be ignored, regardless of what JavaDoc says about it, while startPosition is correctly applied.
Cause:
Digging into CUBA’s code, we found out that in
com.haulmont.cuba.web.gui.components.WebSourceCodeEditor
the field
suggestionExtension
is initialized using a new instance based on the protected inner class of WebSourceCodeEditor itself, which doesn’t support endPosition parameter for selected Suggestion:
Workaround:
To bypass this issue, we didn’t find any other solution than overwrite suggestionExtension field, using reflection, with our own implementation of
com.haulmont.cuba.web.widgets.addons.aceeditor.Suggester
which of course is not the optimal approach, at least for the “reflection” part.
This is our code:
As you can see, it differs from the original one just for the applySuggestion method:
@Override public String applySuggestion(final com.haulmont.cuba.web.widgets.addons.aceeditor.Suggestion suggestion, final String text, final int cursor) { String suggestionText = suggestion.getSuggestionText(); return StringUtils.substring(text, 0, suggestion.getStartPosition() > 0 ? suggestion.getStartPosition() : cursor) + suggestionText + StringUtils.substring(text, suggestion.getEndPosition() > 0 ? Math.min(suggestion.getEndPosition(), text.length()) : cursor); }
Potential Solutions:
As far as we can see, the potential solutions are:
- supporting endPosition parameter in applySuggestion method of WebSourceCodeEditor’s protected inner class
- exposing suggestionExtension field via API to allow overwriting it without using reflection
Are we missing something else?
Thanks in advance and keep up the great work!
Luca R.