A text editor built using C++ and Windows API.
- Tabbed Interface:
- Create New Files:
- Open Existing Files:
- Save:
- Save As:
- Save All:
- Undo/Redo
- Cut, Copy, and Paste
- Language: C++
- Build System: CMake
- Main Components:
TextEditor
: Main application classTabControl
: Manages the tabbed interfaceDocumentText
: Handles text storage and manipulation
- Key Files:
TextEditor.cpp
: Core editor functionalityTabControl.cpp
: Tab managementDocumentText.cpp
: Text document handling
Download from the release https://github.com/nickolasddiaz/NickolasDiaz-Text-Editor/blob/master/nickolasddiazeditor.exe
To build and run NickolasDDiazTextEditor:
- Ensure you have CMake and a C++ compiler installed.
- Clone the repository.
- Navigate to the project directory.
- Run the following commands:
mkdir build cd build cmake .. cmake --build .
https://austinhenley.com/blog/challengingprojects.html
https://www.catch22.net/tuts/neatpad/
The Gap Buffer is a data structure used in text editing to efficiently manage text insertion and deletion. It involves an array with a "gap" between two pieces of text, which allows for efficient editing around that gap
Structure: The gap buffer is implemented in the DocumentText class. It consists of a character array (buffer) with a "gap" in the middle. Gap Positioning: The gap is defined by two indices: gapStart and gaspEnd. Text before gapStart and after gapEnd represents the actual document content. Insertion: When text is inserted, it's placed at the start of the gap. The gapStart is then moved forward, effectively shrinking the gap. Deletion: When text is deleted, the gap expands to cover the deleted region. This is done by adjusting gapStart or gapEnd. Cursor Movement: When the cursor moves, the gap is relocated to the cursor position using the moveGap function. This involves copying text from one side of the gap to the other. Efficiency: This approach makes insertions and deletions at or near the cursor position very efficient, typically O(1) operations. Buffer Expansion: If the gap becomes too small to accommodate new text, the expandBuffer function is called to increase the buffer size.
The editor implements the Command Pattern to provide undo and redo functionality:
Command Interface: An abstract Command class defines the interface for all commands with execute() and undo() methods. Concrete Commands:
InsertCommand: Represents text insertion operations. DeleteCommand: Represents text deletion operations.
Command Execution: When a user types or deletes text, a corresponding command object is created and executed. The command object stores all necessary information to perform and reverse the action. Command History: The CommandHistory class maintains two stacks:
undoStack: Stores executed commands redoStack: Stores undone commands
Undo Operation:
Pops the top command from the undoStack Calls its undo() method Pushes the command onto the redoStack
Redo Operation:
Pops the top command from the redoStack Calls its execute() method Pushes the command back onto the undoStack
Cursor Position Tracking: Each command stores the cursor position after its execution, allowing for accurate cursor placement during undo/redo operations.