adachsoft / text-editor
A stateful in-memory text editor supporting fragment and line edits, regular expression replacement, revert operations, and diffs.
v0.1.0
2026-11-12 05:34 UTC
Requires
- php: >=8.3
- adachsoft/collection: ^3.0
- sebastian/diff: ^6.0 || ^7.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.2
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
- rector/rector: ^2.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-12 04:34:31 UTC
README
A stateful, in-memory PHP text editor for making and inspecting changes without file I/O. It keeps the original content and edit history, making changes easy to review or revert.
Features
- Replace, insert, and delete text fragments or line ranges.
- Apply regular-expression replacements.
- Read line ranges and inspect the edit history.
- Revert the most recent operation or restore the original content.
- Generate structured hunks or a unified diff.
- Supply a custom diff implementation through
TextDiffInterface.
Installation
Install the library with Composer:
composer require adachsoft/text-editor
Quick start
<?php
declare(strict_types=1);
use AdachSoft\TextEditor\TextEditor;
$editor = new TextEditor("Hello, world!\n");
$editor->replaceFragment('world', 'PHP');
echo $editor->getText(); // Hello, PHP!
echo $editor->diffUnified();
$editor->revert();
See the examples for more editing operations.