From fe7135350f64ba10a63626c6f363cc48a0679438 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+orbitalquark@users.noreply.github.com> Date: Tue, 8 Jun 2021 21:37:53 -0400 Subject: Do not attempt to restore the selection when typing after selecting/deleting all text. This extends r3135 to also handle auto-paired characters. --- core/ui.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/ui.lua b/core/ui.lua index 21fcbf80..b006c84a 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -375,8 +375,10 @@ local function restore_buffer_state() view.x_offset = buffer._x_offset or 0 end events.connect(events.BUFFER_AFTER_SWITCH, restore_buffer_state) -events.connect(events.BUFFER_AFTER_REPLACE_TEXT, - function() if buffer.length > 1 then restore_buffer_state() end end) +events.connect(events.BUFFER_AFTER_REPLACE_TEXT, function() + local anchor, pos = buffer._anchor or 0, buffer._current_pos or 0 + if anchor <= buffer.length and pos <= buffer.length then restore_buffer_state() end +end) -- Updates titlebar and statusbar. local function update_bars() -- cgit v1.2.3