Skip to content

Comments

feat/fix: Align the word break behaviour of Aspiers' new text transformation functions more closely with readlines conventions.#211

Open
ariane-emory wants to merge 5 commits intodevfrom
feat/aspiers--readline-additions
Open

feat/fix: Align the word break behaviour of Aspiers' new text transformation functions more closely with readlines conventions.#211
ariane-emory wants to merge 5 commits intodevfrom
feat/aspiers--readline-additions

Conversation

@ariane-emory
Copy link
Owner

@ariane-emory ariane-emory commented Feb 22, 2026

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR is an enhancement/fix to a PR on the upstream repo (anomalyco#6778), which provides additional readline/Emacs-style text transformations, that aligns the word break behaviour more closely with readline/Emacs conventions, addressing the issue that I pointed, out in my recent comments on the upstream PR.

Adam Spiers and others added 3 commits February 2, 2026 22:15
Without this patch, users must manually retype text to change case or
paste deleted content in the TUI prompt, and some keybindings conflict
with other TUI functions.

This is a problem because it slows down text editing and limits the
ability to customize keybindings to match user preferences.

This patch solves the problem by adding configurable shortcuts for
lowercase, uppercase, capitalize word, transpose characters, and yank
operations, along with a kill buffer for storing deleted text.
Punctuation characters (., -, etc.) are now treated as word boundaries
instead of being part of words, matching the behavior of Readline and
Emacs where only alphanumeric characters and underscores are word
constituents.
@ariane-emory ariane-emory changed the title Feat/aspiers readline additions feat/fix: Align the word break behaviour of Aspiers' new text transformation functions more closely with readlines conventions. Feb 22, 2026
- input_delete_word_backward now uses isWordChar() like other word
  operations, treating punctuation as word boundaries
- Remove duplicate input_transpose_characters handler (dead code)
- Add tests for underscore handling and merged-branches.md scenarios
@aspiers
Copy link

aspiers commented Feb 23, 2026

Thanks for this! I noticed your PR while looking at the upstream PR — and I had already pushed an equivalent fix to my branch earlier today (see my comment on the upstream PR).\n\nOur implementations are functionally equivalent: both switch from /\s/ (whitespace) to /\w/ (alphanumeric + underscore) for word character detection. Yours preserves the original branching structure and extracts a nice isWordChar helper; mine simplifies the whole function to a single forward-scan pattern. I may adopt the isWordChar helper for readability — it does make the intent clearer.\n\nI'll compare our test suites too to see if yours covers anything mine doesn't.

@aspiers
Copy link

aspiers commented Feb 23, 2026

I've now pushed a "best of breed" version to my upstream PR that incorporates the best aspects of both of our fixes. Here's a summary of what ended up in the final version:

From your PR:

  • The isWordChar helper function — good for readability and avoiding repeated inline regex literals.
  • The input_transpose_characters entry added to types.gen.ts — your PR caught that this was missing.

Fixes beyond both our initial attempts:
After verifying against Emacs and Readline directly, I found two further issues that affected both our implementations:

  1. _ is not a word character. We both used /\w/ which includes underscore, but Emacs uses its word syntax class (only [A-Za-z0-9]) and Readline uses isalnum(). Neither includes _. So foo_bar is two words, not one.

  2. No "fallback to previous word" when at end of buffer. We both fell back to the previous word when the cursor was past the last word. But Emacs upcase-word/downcase-word is simply a no-op in that situation — verified with emacs --batch. The function now returns null and the handler skips the action.

The final isWordChar is /[A-Za-z0-9]/ and getWordBoundariesForTransformation is now a clean two-phase forward scan: skip non-word chars, advance through word chars, return null if no word found.

- Move isWordChar, getWordBoundaries, and case transformation functions to word.ts
- Use /[A-Za-z0-9]/ for word chars (underscore is now a boundary, matching Readline/Emacs)
- Update tests to import from actual module
- Add isWordChar tests and underscore boundary tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants