Skip to content

minimalReplace assumes exact first-occurrence semantics, but Word searches case-insensitively #592

Description

@kcarnold

minimalReplace (frontend/src/pages/my-words/interaction/editor.ts) shrinks a paragraph rewrite to its changed middle, then grows the needle leftward until the first occurrence is the intended one:

// Hosts replace the FIRST occurrence; grow the needle leftward until the
// first occurrence is the intended one (e.g. second "aa" in "aa b aa").
while (start > 0 && oldText.indexOf(oldStr) !== start) {

That disambiguation is computed with case-sensitive indexOf, but wordEditorAPI.applyEdit searches with matchCase: false. So in a paragraph containing Cat … cat, a needle grown to be unambiguous under indexOf can still be ambiguous to Word, and Word replaces the earlier occurrence — a silent edit in the wrong place.

Narrow: it needs a paragraph with the same text differing only in case, and the grown needle to stay short enough to still collide. Pre-existing; not related to #587, which changed how the model's needles are located, not how host-derived ones are.

Fix

Either make the disambiguation loop match the host's semantics (compare case-insensitively when growing), or — better — remove the assumption entirely by resolving a range instead of a needle, per #589.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions