Skip to content

EOL edge case handled for dw needs to be handled for all other operators #84

@tuurep

Description

@tuurep

Important: I fixed this bug as a byproduct of trying to fix some cw edge cases in
#69, just wanted to open an issue to link to when I send a PR

For d, there's handling for this case:

    foo
      ^
    bar

dw

becomes:

    fo
     ^
    bar

and not:

    fo
bar
^

Handling:

" dw at the end of a line should not consume the newline or leading white
" space on the next line
let l:is_dw = a:mode == 'o' && v:operator == 'd' && l:flags == ''
let l:next_line = l:pos[1] < getpos('.')[1]
if l:is_dw && l:next_line
let l:s = a:uppercase ? s:us : s:s
" newline, leading whitespace, cursor
if search('\m\n\%('.l:s.'\)*\%#', 'bW') != 0
let l:dwpos = getpos('.')
" need to make range inclusive
call setpos('.', l:pos)
normal! v
call setpos('.', l:dwpos)
endif
endif

Bug: this needs to be handled for every operator, with the most obvious example being y

    foo
      ^
    bar

ywp

Expected:

    fooo
       ^
    bar

Got:

    fooo
       ^
(4 leading whitespace)
    bar

With mini.surround

    foo
      ^
    bar

saw)

Expected:

    fo(o)
       ^
    bar

Got:

    fo(o
       ^
    )bar

It looks safe to say that every operator should be included in the handling of this edge
case, it's just that cw has its slight differences, but that doesn't matter for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions