Brahim Elhoube

General

Text Editor

A lightweight C++ text editor built with SFML to study document modeling, cursor movement, file operations, theme switching, undo history, and text selection.

Open project

Abstract

Red Text is a lightweight desktop text editor built with C++ and SFML. The project investigates how editor primitives such as document lines, cursor movement, file loading, saving, theme switching, undo history, and text selection can be modeled in an object-oriented GUI application.

Problem

Text editors appear simple at the interface level, but they require careful state management. Cursor placement, line storage, selection ranges, document mutations, and undo behavior all interact with each other and must remain consistent after every edit.

Method

Application Structure

I started the project by installing SFML which is a library for writing games in C++. SFML helps developers create games by providing them with cross-platform access to graphics and input devices. Application header I created the necessary classes for the operation of the application, such as Document, Cursor, EditorLine etc.

File and Theme Operations

After implementing the core editor behavior, I added dark/light mode switching and the ability to open a local file from the user's device.

I added a header to hold the opened file name, and list the main action: open a file, save the content, and change the theme. Application header

Edit History

Undo support became necessary once the editor could modify loaded content. To make this possible, I designed a History class that stores content snapshots and allows navigation between previous document states.

Feel free to make mistakes, you can always undo them. Application header

Text Selection

Text selection was the most challenging feature because the document is stored as lines and selection behavior must account for multiple cases:

  • When the user selects a portion of a line
  • When the user selects many lines
  • When the user selects the whole line
  • When the selected content is copied, cut, or deleted

Addressing this challenge involved establishing a method to represent selected text consistently so the selected content could be manipulated without introducing unnecessary complexity into the codebase.

Outcome

The project provided practical experience with C++, object-oriented design, GUI state, and editor internals. It also made the hidden complexity of everyday tools more visible by implementing core behaviors from first principles.