Skip to content

Refactor: extract SelectionModel, UndoStack, Clipboard from TextBox (…#667

Open
asshifasultana wants to merge 2 commits into
mabe02:masterfrom
asshifasultana:refactor
Open

Refactor: extract SelectionModel, UndoStack, Clipboard from TextBox (…#667
asshifasultana wants to merge 2 commits into
mabe02:masterfrom
asshifasultana:refactor

Conversation

@asshifasultana

Copy link
Copy Markdown

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 the gui2.textbox package, improving separation of concerns and maintainability.

No behavior changes are introduced.


Problem

TextBox previously 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 | 41

TextBox now delegates these responsibilities through thin wrapper methods, preserving the existing public API and behavior.


Verification

  • mvn clean compileBUILD SUCCESS

  • All TextBox-related tests pass

  • Existing unrelated failures in Button / CheckBox remain unchanged


Files Changed

4 files changed, +215 / -0

  • gui2/TextBox.java (+67) — Added delegator methods

  • gui2/textbox/TextBoxClipboard.java (+41) — New

  • gui2/textbox/TextBoxSelectionModel.java (+47) — New

  • gui2/textbox/TextBoxUndoStack.java (+60) — New

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 this pull request may close these issues.

1 participant