martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.2k stars 258 forks source link

INSERT mode autocomplete by <C-n> only completes the primary selection #949

Open sauterp opened 3 years ago

sauterp commented 3 years ago

Version commit: 1a958f221404b09cb8b0612fb34301e6b9783cf9 (latest master at this time) vis -v vis v0.7-29-g1a958f2 +curses +lua +acl

How to reproduce

  1. Open vis.
  2. Type any word like "hello".
  3. Create more than one selection().
  4. Type the word partially like "he".
  5. Hit while in insert mode.
  6. Hit enter when "hello" is selected.

Only the primary selection will be completed. It's not a big problem, but I would find it more convenient and consistent with other features if the autocompletion would apply to all selections, like pasting. Unlike pasting, I wouldn't have a different autocomplete suggestion for each selection. That's not feasible I think. I would implement it such that the suggestions are generated based on the primary selections cursor. What do you think?

ninewise commented 3 years ago

I've seen this as well but learned to live with it. It'd be nice to get the same (primary) completion on every selection though.

jpaulogg commented 3 years ago

The Vis:insert function inserts keys at all cursor positions of active window. I copied few lines from digraph.lua and it is working with multiple selections and also in replace mode.

Just replace this line with that:

    if vis.mode == vis.modes.INSERT then
        vis:insert(out)
    elseif vis.mode == vis.modes.REPLACE then
        vis:replace(out)
    end

PS: This only works when the prefixes of all selections are the same

sauterp commented 3 years ago

The Vis:insert function inserts keys at all cursor positions of active window. I copied few lines from digrpah.lua and it is working with multiple selections and also in replace mode.

Just replace this line with that:

  if vis.mode == vis.modes.INSERT then
      vis:insert(out)
  elseif vis.mode == vis.modes.REPLACE then
      vis:replace(out)
  end

PS: This only works when the prefixes of all selections are the same

Thank you for the hint, I extended on this in my PR. It will only autocomplete those selections which share the same prefix as the primary selection, the others remain unchanged.

I'm not sure if this is a good solution for everyone, but it would work for me.