diff --git a/src/lua_bindings/mod.rs b/src/lua_bindings/mod.rs index 290df7a..7cf0bc4 100644 --- a/src/lua_bindings/mod.rs +++ b/src/lua_bindings/mod.rs @@ -1309,12 +1309,16 @@ fn run_buffer_edit( bypass_intercept: bool, ) -> mlua::Result { // Arc 6 Stage 2 (Q#FD19): the interactive-Lua-command unfold seam. - // Hooked HERE — above both `run_managed_edit` and `run_bypass_edit` — - // so an interactive command that passes `bypass_intercept` does not - // escape the widening. Keyed on where the edit LANDS, read before - // `op` is consumed below. - unfold_before_interactive_lua_edit(lua, id, edit_start_of(&op)); + // BOTH paths are covered — hooking only `run_managed_edit` would let + // an interactive `bypass_intercept` edit escape — but each keys on + // *its own* effective edit site (round-5 F1): + // + // - bypass applies `op` verbatim, so the site is known right here; + // - managed runs the intercept chain first, and an intercept may + // legally relocate `pos` / `start` / `end`, so only the op the + // chain settles on names where the edit will land. if bypass_intercept { + unfold_before_interactive_lua_edit(lua, id, edit_start_of(&op)); run_bypass_edit(lua, id, op) } else { run_managed_edit(lua, id, op) @@ -1359,6 +1363,12 @@ fn edit_start_of(op: &EditOp<'_>) -> u64 { /// [`apply_active_edit`](crate::editor_core::EditorCore::apply_active_edit)'s /// funnel keys on the point; only this Lua path can diverge. /// +/// "Edit site" means the **effective** one (round-5 F1). On the managed +/// path a buffer intercept may legally rewrite `pos` / `start` / `end` +/// before the op is applied, so [`run_managed_edit`] calls this *after* +/// the intercept chain settles; only [`run_bypass_edit`], which applies +/// its op verbatim, can name the site up front. +/// /// Matches Stage 1's data-API exemption: `pmacs.buffer.insert` called /// from a plugin, a hook, or a bare Lua chunk unfolds nothing. fn unfold_before_interactive_lua_edit(lua: &Lua, id: BufferId, edit_start: u64) { @@ -1435,6 +1445,19 @@ fn run_managed_edit(lua: &Lua, id: BufferId, op: EditOp<'_>) -> mlua::Result