Skip to content

TextChanged event semantics are confusing #215

@BDisp

Description

@BDisp

Summary

TextDocument.TextChanged is misleading and collides with the IDocument.TextChanged semantics.

Description

TextDocument exposes a public event EventHandler TextChanged, but the IDocument interface also defines event EventHandler<TextChangeEventArgs> TextChanged.

In TextDocument:

  • public event EventHandler TextChanged is raised by FireChangeEvents() after EndUpdate() / change group completion.
  • IDocument.TextChanged is implemented explicitly and raised by DoReplace() immediately after each individual document change, with TextChangeEventArgs.

That means:

  • TextDocument doc = new TextDocument(); doc.TextChanged += ... receives a change-completed notification without any change details.
  • ((IDocument)doc).TextChanged += ... receives the actual per-change event with TextChangeEventArgs.

This is very likely to confuse consumers and causes surprising behavior.

Expected behavior

  • TextDocument.TextChanged should either match the IDocument.TextChanged semantics/signature,
  • or the public event should be renamed to something like ChangeCompleted / UpdateFinished.

The explicit interface implementation should remain consistent and clear.

Suggested fix

  • Rename or clarify the public TextChanged event in TextDocument so it does not collide with IDocument.TextChanged.
  • Prefer public event EventHandler ChangeCompleted; and keep IDocument.ChangeCompleted aliasing it.
  • Preserve IDocument.TextChanged as the per-change event with TextChangeEventArgs.

Location

src/Terminal.Gui.Editor/Document/TextDocument.cs (TextChanged declaration and FireChangeEvents() / DoReplace() behavior)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions