Refactor: extract SelectionModel, UndoStack, Clipboard from TextBox (…#667
Open
asshifasultana wants to merge 2 commits into
Open
Refactor: extract SelectionModel, UndoStack, Clipboard from TextBox (…#667asshifasultana wants to merge 2 commits into
asshifasultana wants to merge 2 commits into
Conversation
…Phase 3 - God Class)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR is Phase 3 of an ongoing God Class decomposition refactor for
TextBox.It extracts three independent concerns from
TextBox.java(≈950 lines) into focused collaborator classes under thegui2.textboxpackage, improving separation of concerns and maintainability.No behavior changes are introduced.
Problem
TextBoxpreviously handled multiple unrelated responsibilities in a single class, including:Text content management
Line storage and updates
Caret positioning
Selection state
Undo/redo history
Clipboard buffer
Rendering logic
Change listeners
This made the class difficult to maintain, test, and extend.
Solution
Extracted the following responsibilities into dedicated helper classes:
New Class | Responsibility | Lines -- | -- | -- TextBoxSelectionModel | Manages selection start/end and text extraction | 47 TextBoxUndoStack | Maintains bounded LIFO history (size 50) for undo/redo | 60 TextBoxClipboard | Handles clipboard read/write for copy/paste | 41TextBoxnow delegates these responsibilities through thin wrapper methods, preserving the existing public API and behavior.Verification
mvn clean compile→ BUILD SUCCESSAll TextBox-related tests pass
Existing unrelated failures in
Button/CheckBoxremain unchangedFiles Changed
4 files changed, +215 / -0
gui2/TextBox.java(+67) — Added delegator methodsgui2/textbox/TextBoxClipboard.java(+41) — Newgui2/textbox/TextBoxSelectionModel.java(+47) — Newgui2/textbox/TextBoxUndoStack.java(+60) — New