Skip to content

[Bug] paste-detection returns wrong addedText on deletions #979

Description

@akramcodez

Description

If a user deletes text, newText.slice(this.lastInputLength) in source/utils/paste-detection.ts returns garbage characters from the middle of the text instead of early-returning.

Environment

  • OS: (e.g., macOS 14.0, Ubuntu 22.04, Windows 11)
  • Node version: (run node --version)
  • Nanocoder version: (run nanocoder --version)
  • Provider: (e.g., Ollama, OpenRouter, OpenAI-compatible API)
  • Model: (e.g., llama3.2, claude-3.5-sonnet)

Steps to Reproduce

  1. Delete text in the prompt input.
  2. Inspect the paste detection event payloads.

Expected Behavior

The logic should early-return if charsAdded <= 0.

Actual Behavior

It processes a negative offset and returns garbage characters.

Logs/Screenshots

N/A

Additional Context

  • I have searched existing issues to ensure this is not a duplicate
  • I can reproduce this issue consistently
  • This issue occurs with the latest version of nanocoder

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions