Search by

adachsoft / text-editor

Arkadiusz Adach

A stateful in-memory text editor supporting fragment and line edits, regular expression replacement, revert operations, and diffs.

Package info

gitlab.com/a.adach/text-editor

Issues

pkg:composer/adachsoft/text-editor

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-12 05:34 UTC

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.