Files
neovim/runtime/lua/vim/_meta/events.lua
Justin M. Keyes 47cd769ed5 feat(cmdatom): mappings capture continuation
Problem:
A mapping that ends mid-operation (`nnoremap ,D d`) emits a content-free
"mapping" atom plus a `pending` field, and the "continuation" motion
arrives as a sibling atom. Consumers must stitch the two together (which
has broken cases, e.g. Insert-opening mappings (",i") lose their session
entirely).

- ",i": the session atom is dropped bc the mapping RHS is consumed
  before the session starts (typebuf_maplen()==0), so
  atom_is_user_input()=false.
- ":normal"-in-opfunc: the opfunc internal "v..y" session (a) became
  kVatomTyped just because the deferred composite was open, masking the
  real operator capture via atom_captures, and (b) its nested frames
  re-derived the outer redo.
- "Motion" based on `moved=true`, has false negatives.
- `CmdAtom.remap` is unnecessary, and clutters the docs/usage.

Solution:
- Introduce `frame_id` to identify CmdFrames.
- Classify `type=motion` better, via `NV_MOTION` flag on the `nv_cmds` table.
- Drop `CmdAtom.pending`, `CmdAtom.remap`.
- Defer atom_composite_end() at the clock edge while an operator is
  pending, Visual is active, or `restart_edit` is set: the composite
  keeps collecting, so the continuation is captured in the mapping atom.
- ",i": Now an open composite counts as user input.
- ":normal"-in-opfunc: Now handled correctly.
- `remap` is now decided by `composite.payload || 0 subatoms`.
  atom_payload_mark() records the read the resolution never captures.
- `toplevel` is now decided by `CmdFrame.parent == NULL`.

before/after:

    INPUT       BEFORE                             AFTER
    ---------------------------------------------------------------------
    ,D w        {mapping lhs=,D pending=operator}  {operator lhs=,Dw keys=dw}
                + {operator keys=dw}
    ysiw"       {mapping lhs=ys pending=operator}  {operator lhs=ysiw" keys=g@iw"}
                + {operator lhs=g@iw"}
    ,v d        {mapping pending=visual}           {visual lhs=,vd keys=viwd}
                + {visual lhs=viwd}
    ,i XY<Esc>  {normal keys=i lhs=,iXY<Esc>}      {insert keys=1iXY<Esc> text=XY}
2026-08-22 17:29:34 +02:00

83 lines
2.8 KiB
Lua

--- @meta
-- This file is NOT generated, edit it directly.
--
-- See also `vim.api.keyset.events` in `api_keysets.gen.lua`.
error('Cannot require a meta file')
--- Data for the CmdAtom event.
--- @class vim.event.cmdatom.data
--- @field atoms? vim.event.cmdatom.data[] Subatoms of a composite (mapping, Visual sequence).
--- @field changed boolean Changed the buffer.
--- @field cmd? string Command/motion/object name ("w", "f", "iw", "gJ").
--- @field cmdarg? string Operand of `cmd` ("fx" => "x").
--- @field count? integer Effective count.
--- @field keys? string Resolved keysequence, raw bytes. Replay via `feedkeys(keys, 'n')`. Nil: lossy capture, replay via `feedkeys(lhs, 'm')` instead. Empty: unreplayable.
--- @field lhs string High-level user input: mapping LHS + any payload it read, or macro register ("gj", "ds'", "@q"). Raw bytes.
--- @field motionforce? 'v'|'V'|'<C-V>' forced-motion type.
--- @field moved? boolean Moved the cursor.
--- @field operator? string Operator name ("d", "g~", "g@"). key-notation.
--- @field pos? [integer,integer] Cursor before the action: 1-indexed row, 0-indexed column.
--- @field reg? string Register name.
--- @field text? string Inserted text, or the Ex/search cmdline.
--- @field type 'excmd'|'insert'|'jump'|'mapping'|'motion'|'mouse'|'normal'|'operator'|'scroll'|'visual'
--- @field undoseq? integer Undo state after the action (`undotree().seq_cur`). Decreases on undo.
--- @class vim.event.lspattach.data
--- @field client_id integer
--- @class vim.event.lspdetach.data
--- @field client_id integer
--- @class vim.event.lspnotify.data
--- @field client_id integer
--- @field method string
--- @field params table
--- @class vim.event.lspprogress.data
--- @field client_id integer
--- @field params lsp.ProgressParams
--- @class vim.event.lsprequest.data
--- @field client_id integer
--- @field request_id integer
--- @field request table
--- @class vim.event.lsptokenupdate.data
--- @field client_id integer
--- @field token table
--- @class vim.event.markset.data
--- @field name string
--- @field line integer
--- @field col integer
--- @class vim.event.packchanged.data
--- @field active boolean
--- @field kind string
--- @field spec vim.pack.Spec
--- @field path string
--- @class vim.event.packchangedpre.data : vim.event.packchanged.data
--- @class vim.event.progress.data
--- @field id any
--- @field text string[]
--- @field data? table
--- @field percent? integer
--- @field source? string
--- @field status? string
--- @field title? string
--- @class vim.event.tabmoved.data
--- @field tabnr_old integer
--- @field tabnr_new integer
--- @class vim.event.termrequest.data
--- @field sequence string
--- @field terminator string
--- @field cursor integer[]
--- @class vim.event.termresponse.data
--- @field chan integer
--- @field sequence string