RFR: 8366201: RichTextArea: remove allowUndo parameter

Andy Goryachev angorya at openjdk.org
Wed Oct 22 23:19:41 UTC 2025


On Wed, 22 Oct 2025 13:38:45 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> Original user feedback (see https://mail.openjdk.org/pipermail/openjfx-discuss/2025-August/000267.html ) called for adding an `allowUndo` parameter to `applyStyle()` and `setStyle()` methods similarly to `replaceText()`.
>> 
>> Upon further analysis, the `allowUndo` parameter was a mistake: allowing the application code to disable creating undo/redo entries messes up the internal undo/redo stack.
>> There is an internal need (`UndoableChange`), but it should not be exposed via public API.
>> 
>> This PR also adds `isUndoRedoEnabled()` and `setUndoRedoEnabled()` to the `StyledTextModel`, as well as its forwarding aliases to `RichTextArea` to allow for the application to disable undo/redo temporarily, for example, when building a document from multiple segments.
>> 
>> WARNING this is an incompatible change, permitted because of the incubator.
>> 
>> There remains a possible issue with currently unlimited size of the undo/redo stack - perhaps we should limit its depth to maybe 100-200 entries, see https://bugs.openjdk.org/browse/JDK-8370447 .
>
> I agree that having this as a per-method argument doesn't make sense.
> 
> I think it's worth considering a future enhancement to add a property to enable or disable the undo feature, with a default of `true`. When set to `true`, it stores entries in the undo stack and enables undo/redo. When set to `false`, it discards the current stack and doesn't store anything or allow undo/redo until the next time it is set to true.

Thank you @kevinrushforth for suggesting the `enableUndo` (`enableUndoRedo` ?) property.

Consider a scenario of building a (large) document programmatically: in the absence of such a property, the undo entries will be created, consuming the resources, to be immediately discarded by `clearUnoRedo()` at the end, as suggested earlier.  A better solution is to indeed explicitly disable the undo/redo via a new property.  This is especially helpful when we consider that currently the undo/redo stack has no limit - see also https://bugs.openjdk.org/browse/JDK-8370447 .

Converting this PR back to Draft to add the property, since the code is interdependent and we'll need a CSR anyway.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1941#issuecomment-3433482155


More information about the openjfx-dev mailing list