Skip to content

Fix Delete(Sub)Word commands to respect active selection - #3987

Merged
JoeKar merged 2 commits into
micro-editor:masterfrom
masmu:fix/delete-word-selection
Nov 12, 2026
Merged

JoeKar merged 2 commits into
micro-editor:masterfrom
masmu:fix/delete-word-selection

Conversation

@masmu

@masmu masmu commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Previously, Delete(Sub)WordLeft/Right commands would delete the word or subword adjacent to the cursor, even if the user had actively selected a range of text.

This PR modifies DeleteWordRight, DeleteWordLeft, DeleteSubWordRight and DeleteSubWordLeft.
These functions now check h.Cursor.HasSelection().
- If a selection exists, they delete the selected text.
- If a selection does not exist, they proceed with the original behavior (select word/subword and delete it).

This ensures micro behaves consistently with other modern text editors. When a user explicitly selects a range of text, a delete command should remove that specific range, rather than modifying the buffer based solely on cursor position relative to word boundaries.

Fixes #3984

Comment thread internal/action/defaults_darwin.go Resolved
Comment thread internal/action/defaults_other.go Resolved
Comment thread internal/action/actions.go Resolved
@masmu
masmu force-pushed the fix/delete-word-selection branch from 403ea57 to bb9fd3e Compare February 9, 2026 14:20
@JoeKar
JoeKar requested a review from dmaluka July 15, 2026 17:57
Comment thread internal/action/defaults_darwin.go Resolved
Comment thread internal/action/actions.go Resolved
masmu added 2 commits November 6, 2026 09:26
Delete(Sub)WordLeft/Right deleted the word adjacent to the cursor
even when the user had an active selection, so text outside the
selection was deleted. These actions now delete the current selection
when one exists, and only select a word/subword to delete when there
is none. This makes the behavior predictable and matches standard text
editing conventions.

Fixes micro-editor#3984
Add a DeleteSelections action that deletes the selection of every
cursor when any selection is active, and returns true so that chained
actions stop. It is not a MultiAction because it iterates all cursors
itself, which gives a single global check for active selections and
keeps the outcome predictable in multi-cursor edits.

The default keybindings are unchanged. Users can chain the action
with the deletion action they prefer, for example
`DeleteSelections|DeleteWordLeft`.
@masmu
masmu force-pushed the fix/delete-word-selection branch from bb9fd3e to 4b92630 Compare November 6, 2026 08:30
@JoeKar
JoeKar merged commit 02409a3 into micro-editor:master Nov 12, 2026
6 checks passed
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.

Delete(Sub)?Word does not respect selection ranges

3 participants