Skip to content

Commit

Permalink
Fixed potential crash when manually emitting events.UPDATE_UI witho…
Browse files Browse the repository at this point in the history
…ut an argument.

Raising an error results in an infinite loop, so just silently exit the handler.
  • Loading branch information
orbitalquark committed Jan 16, 2025
1 parent dbcd91c commit db9e26a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ events.connect(events.APPLEEVENT_ODOC,

-- Sets buffer statusbar text.
events.connect(events.UPDATE_UI, function(updated)
if updated & 3 == 0 then return end -- ignore scrolling
if not updated or updated & 3 == 0 then return end -- ignore scrolling
local text = not CURSES and '%s %d/%d %s %d %s %s %s %s' or
'%s %d/%d %s %d %s %s %s %s'
local pos = buffer.current_pos
Expand Down
4 changes: 2 additions & 2 deletions modules/textadept/editing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ end, 1)

-- Highlights matching braces.
events.connect(events.UPDATE_UI, function(updated)
if updated & 3 == 0 then return end -- ignore scrolling
if not updated or updated & 3 == 0 then return end -- ignore scrolling
if brace_matches[buffer.char_at[buffer.current_pos]] then
local match = buffer:brace_match(buffer.current_pos, 0)
local f = match ~= -1 and view.brace_highlight or view.brace_bad_light
Expand All @@ -563,7 +563,7 @@ end)

-- Highlight all instances of the current or selected word.
events.connect(events.UPDATE_UI, function(updated)
if updated & buffer.UPDATE_SELECTION == 0 or ui.find.active then return end
if not updated or updated & buffer.UPDATE_SELECTION == 0 or ui.find.active then return end
if M.highlight_words == M.HIGHLIGHT_NONE then return end
buffer.indicator_current = M.INDIC_HIGHLIGHT
buffer:indicator_clear_range(1, buffer.length)
Expand Down
3 changes: 2 additions & 1 deletion modules/textadept/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ local function deselect()
buffer:set_empty_selection(buffer._deselect_pos)
end
events.connect(events.UPDATE_UI, function(updated)
if updated & 3 > 0 and buffer.selection_empty then buffer._deselect_pos = buffer.current_pos end
if not updated or updated & 3 == 0 or not buffer.selection_empty then return end
buffer._deselect_pos = buffer.current_pos
end)
--- Wrapper around `buffer:upper_case()` and `buffer:lower_case()`.
local function change_case(upper)
Expand Down
2 changes: 1 addition & 1 deletion modules/textadept/snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ setmetatable(M,
-- Update snippet transforms when text is added or deleted.
events.connect(events.UPDATE_UI, function(updated)
if not active_snippet then return end
if updated & buffer.UPDATE_CONTENT > 0 then active_snippet:update_transforms() end
if updated and updated & buffer.UPDATE_CONTENT > 0 then active_snippet:update_transforms() end
if #keys.keychain == 0 then ui.statusbar_text = _L['Snippet active'] end
end)

Expand Down

0 comments on commit db9e26a

Please sign in to comment.