micro-editor / micro-editor/micro

`Delete(Sub)?Word` does not respect selection ranges

Open
#3,984 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
29.6k
Forks
1.4k
Avg merge
2d 18h
Merged PRs (30d)
10

Description

Description

In short, when InSelection — it treats the End/Start of the selection, for Right/Left direction respectively, as the current cursor position, and additionally yoinks the adjacent symbols, instead of deleting what's between selection ranges.

As you can see, after Undoing, it shows the actual area that was affected. Utterly irritating and highly inconvenient.

In my opinion, selection should always take priority in such cases, as the user has consciously chosen to interact with that specific area and this should be respected. Regardless of the navigation mode.

UPD.1

Alternatively, an additional action called DeleteInSelection is needed, at least. So it could be easily combined as DeleteInSelection|Delete(Sub)?Word(Left/Right) per user preference.

Assuming the current behavior is intentional, of course. With TUI apps, you never know what's a bug and what's a feature really...

UPD.2

My sloppy attempt at solving this locally
  • plug/custom/main.lua

    
    function preventHastyDeletion(bp)
      local cursors = bp.Buf:GetCursors()
      local selection
      for c = #cursors, 1, -1 do
        c = cursors[c]
        if c:HasSelection() then
          c:DeleteSelection()
          selection = true
        end
      end
      return selection
    end
    
    
  • /bindings.json

    
    {
      ...
      , "Alt-Backspace"      : "lua:custom.preventHastyDeletion|DeleteWordLeft"
      , "OldBackspace"       : "lua:custom.preventHastyDeletion|DeleteSubWordLeft"
      , "Shift-OldBackspace" : "lua:custom.preventHastyDeletion|SelectToStartOfLine&Backspace"
      , "Alt-Delete"         : "lua:custom.preventHastyDeletion|DeleteWordRight"
      , "Delete"             : "lua:custom.preventHastyDeletion|DeleteSubWordRight"
      , "Shift-Delete"       : "lua:custom.preventHastyDeletion|SelectToEndOfLine&Delete"
      ...
    }
    
    

It does pretty much what I need, although I still think that this should be part of the core logic. Also, not sure if this is the most optimal solution possible.


Environment
  • Version: 2.0.16-dev.15 ( 3a7403bd )
  • OS: -
  • Terminal: -

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the core handling of the DeleteWord and DeleteSubWord actions when InSelection is active, using the behavior described in the reproduction. The plug/custom/main.lua workaround shows the intended selection-first result; done means these actions delete the selected range without consuming adjacent symbols, while preserving the existing directional behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, lua
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.