Overview
The ZepEditor class is the central component of the Zep text editor library. It manages all buffers, editor modes, tab windows, syntax providers, and coordinates the overall editing experience.
Architecture
Editor
Buffers
Modes -> (Active BufferRegion)
Display
BufferRegions (->Buffers)
- A buffer is an array of chars in a gap buffer with insert, delete, and search operations
- A display shows a collection of regions and editor controls in a window
- A buffer region is a single view onto a buffer inside the main display
- Multiple regions can refer to the same buffer (N Regions : N Buffers)
Constructor
ZepEditor
ZepEditor(ZepDisplay* pDisplay, const fs::path& root, uint32_t flags = 0, IZepFileSystem* pFileSystem = nullptr);
Pointer to the display implementation that will render the editor
Root path to search for a config file
Editor flags from ZepEditorFlags enum:
None (0): Default behavior
DisableThreads (1 << 0): Disable background threading
FastUpdate (1 << 1): Enable fast update mode
Custom file system implementation, or nullptr to use default
Configuration
LoadConfig
void LoadConfig(const fs::path& config_path);
void LoadConfig(std::shared_ptr<cpptoml::table> spConfig);
Path to TOML configuration file
spConfig
std::shared_ptr<cpptoml::table>
Parsed TOML configuration table
Load editor configuration from a file or parsed TOML table.
SaveConfig
void SaveConfig(std::shared_ptr<cpptoml::table> spConfig);
spConfig
std::shared_ptr<cpptoml::table>
TOML table to save current configuration to
GetConfig
EditorConfig& GetConfig();
Returns a reference to the current EditorConfig which includes:
showScrollBar: Show/hide scrollbar
style: Normal or Minimal editor style
lineMargins: Margins around lines
showLineNumbers: Enable/disable line numbers
shortTabNames: Use shortened tab names
cursorLineSolid: Solid cursor line highlighting
backgroundFadeTime: Background fade animation duration
Buffer Management
InitWithFile
ZepBuffer* InitWithFile(const std::string& str);
str
const std::string&
required
Path to the file to open
Initialize the editor with a file. Returns pointer to the created buffer.
InitWithFileOrDir
ZepBuffer* InitWithFileOrDir(const std::string& str);
str
const std::string&
required
Path to file or directory
Initialize with a file or directory (creates tree view for directories).
InitWithText
ZepBuffer* InitWithText(const std::string& strName, const std::string& strText);
strName
const std::string&
required
Name for the buffer
strText
const std::string&
required
Initial text content
Create a new buffer with specified name and text content.
GetFileBuffer
ZepBuffer* GetFileBuffer(const fs::path& filePath, uint32_t fileFlags = 0, bool create = true);
Flags from FileFlags enum (ReadOnly, Locked, etc.)
Create buffer if it doesn’t exist (default: true)
Get or create a buffer for a file path.
GetEmptyBuffer
ZepBuffer* GetEmptyBuffer(const std::string& name, uint32_t fileFlags = 0);
name
const std::string&
required
Name for the empty buffer
Create a new empty buffer with the specified name.
SaveBuffer
void SaveBuffer(ZepBuffer& buffer);
void SaveBufferAs(ZepBuffer& buffer, fs::path filePath);
Path for Save As operation
Save a buffer to disk or save as a new file.
GetBuffers
const tBuffers& GetBuffers() const;
Returns all buffers managed by the editor as a std::deque<std::shared_ptr<ZepBuffer>>.
GetActiveBuffer
ZepBuffer* GetActiveBuffer() const;
Returns the currently active buffer.
RemoveBuffer
void RemoveBuffer(ZepBuffer* pBuffer);
Remove a buffer from the editor.
Window Management
AddTabWindow
ZepTabWindow* AddTabWindow();
Create and add a new tab window to the editor.
RemoveTabWindow
void RemoveTabWindow(ZepTabWindow* pTabWindow);
Remove a tab window from the editor.
GetActiveTabWindow
ZepTabWindow* GetActiveTabWindow() const;
Returns the currently active tab window.
SetCurrentTabWindow
void SetCurrentTabWindow(ZepTabWindow* pTabWindow);
Tab window to make active
NextTabWindow / PreviousTabWindow
void NextTabWindow();
void PreviousTabWindow();
Navigate to the next or previous tab window.
GetActiveWindow
ZepWindow* GetActiveWindow() const;
Returns the currently active window.
SetCurrentWindow
void SetCurrentWindow(ZepWindow* pWindow);
FindBufferWindows
std::vector<ZepWindow*> FindBufferWindows(const ZepBuffer* pBuffer) const;
Find all windows displaying a specific buffer.
Mode Management
RegisterGlobalMode
void RegisterGlobalMode(std::shared_ptr<ZepMode> spMode);
spMode
std::shared_ptr<ZepMode>
required
Mode to register (Vim, Standard, etc.)
Register an editor mode globally.
SetGlobalMode
void SetGlobalMode(const std::string& currentMode);
currentMode
const std::string&
required
Name of the mode to activate
Set the active global editor mode.
GetGlobalMode
ZepMode* GetGlobalMode();
Returns the current global mode.
RegisterBufferMode
void RegisterBufferMode(const std::string& strExtension, std::shared_ptr<ZepMode> spMode);
strExtension
const std::string&
required
File extension to associate with mode
spMode
std::shared_ptr<ZepMode>
required
Mode for this file type
Register a mode for specific file extensions.
Syntax and Theme
RegisterSyntaxFactory
void RegisterSyntaxFactory(const std::vector<std::string>& mappings, SyntaxProvider factory);
mappings
const std::vector<std::string>&
required
File extensions or patterns
Factory function to create syntax highlighter
Register a syntax highlighter factory for file types.
GetTheme
ZepTheme& GetTheme() const;
Get the current editor theme.
Registers and Clipboard
SetRegister / GetRegister
void SetRegister(const std::string& reg, const Register& val);
void SetRegister(const char reg, const Register& val);
const Register& GetRegister(const std::string& reg);
const Register& GetRegister(const char reg);
reg
const std::string& | char
required
Register name (single character or string)
Register value containing text and line-wise flag
Manage Vim-style registers for storing text fragments.
ReadClipboard / WriteClipboard
void ReadClipboard();
void WriteClipboard();
Interact with system clipboard.
Display and Rendering
Display
Render the editor to the display.
SetDisplayRegion
void SetDisplayRegion(const NVec2f& topLeft, const NVec2f& bottomRight);
Top-left corner of display region
Bottom-right corner of display region
Set the display area for the editor.
GetDisplay
ZepDisplay& GetDisplay() const;
Get the display implementation.
OnMouseMove
bool OnMouseMove(const NVec2f& mousePos);
Mouse position in window coordinates
Handle mouse movement. Returns true if handled.
OnMouseDown / OnMouseUp
bool OnMouseDown(const NVec2f& mousePos, ZepMouseButton button);
bool OnMouseUp(const NVec2f& mousePos, ZepMouseButton button);
Mouse button: Left, Middle, Right, or Unknown
Handle mouse button events.
OnMouseWheel
bool OnMouseWheel(const NVec2f& mousePos, float scrollDistance);
Handle mouse wheel scrolling.
Commands
RegisterExCommand
void RegisterExCommand(std::shared_ptr<ZepExCommand> spMode);
spMode
std::shared_ptr<ZepExCommand>
required
Ex command to register
Register a Vim-style ex command (like :w, :q, etc.).
FindExCommand
ZepExCommand* FindExCommand(const std::string& strName);
strName
const std::string&
required
Command name to find
Find a registered ex command by name.
SetCommandText
void SetCommandText(const std::string& strCommand);
strCommand
const std::string&
required
Command text to display
Set the command line text.
GetCommandText
std::string GetCommandText() const;
Get the current command line text.
Messaging and Events
Broadcast
bool Broadcast(std::shared_ptr<ZepMessage> payload);
payload
std::shared_ptr<ZepMessage>
required
Message to broadcast to all registered components
Broadcast a message to all registered components. Returns true if handled.
RegisterCallback / UnRegisterCallback
void RegisterCallback(IZepComponent* pClient);
void UnRegisterCallback(IZepComponent* pClient);
Component to register/unregister for notifications
Manage component notification subscriptions.
Utility Methods
GetFileSystem
IZepFileSystem& GetFileSystem() const;
Get the file system interface.
GetThreadPool
ThreadPool& GetThreadPool() const;
Get the thread pool for background operations.
RequestRefresh
void RequestRefresh();
bool RefreshRequired();
Request a display refresh or check if refresh is needed.
Reset
Reset the editor to initial state.
RequestQuit
Request the editor to quit.
Usage Example
#include <zep/editor.h>
#include <zep/mode_vim.h>
// Create display implementation
auto* pDisplay = new MyZepDisplay();
// Create editor with root path and default settings
ZepEditor editor(pDisplay, "/path/to/config");
// Register Vim mode
auto spVim = std::make_shared<ZepMode_Vim>(editor);
editor.RegisterGlobalMode(spVim);
editor.SetGlobalMode("vim");
// Open a file
ZepBuffer* pBuffer = editor.InitWithFile("main.cpp");
// Create a tab window and display
ZepTabWindow* pTab = editor.AddTabWindow();
// Main loop
while (running) {
editor.Display();
// Handle input...
}