[code] [textadept] The UPDATE_UI event

From: Hugh Low <hughlow3.att.live.co.uk>
Date: Wed, 23 Mar 2016 02:59:09 +0000

Hello Mitchell.

I’ve noticed that each time a character is added to a buffer, the ‘UPDATE_UI’ event is emitted up to 4 times (normally 3) with bitmask 1 (buffer.UPDATE_CONTENT). Additionally, when a character is deleted, the event is emitted twice with bitmasks 3 then 1. The following code illustrates this:

local counter, tbl = 0, {};
events.connect(events.UPDATE_UI, function(mask)
        counter, tbl[15] = (counter + 1), nil;
        table.insert(tbl, 1, string.format('[%d] = %d', counter, mask or 0));
        ui.statusbar_text = table.concat(tbl, ', ');
end);

I wanted to let you know just in case this behaviour is not intended.

I have appended the following to my ‘~/.textadept/init.lua’ file to prevent the extra emissions:

local content_bit, previous_pos = buffer.UPDATE_CONTENT;

local content_and_sel_bits = (content_bit + buffer.UPDATE_SELECTION);

events.connect(events.UPDATE_UI, function(mask)
        if (not mask) or (mask > content_and_sel_bits) then
                return; -- changing buffers or scrolling
        end
        local current_pos = buffer.current_pos;
        if (mask == content_bit) and (current_pos == previous_pos) then
                return false; -- prevent calls to subsequent handlers
        end
        previous_pos = current_pos;
end, 1); -- make it the first handler to be called

Although I’ve not noticed any issues so far after adding this code, can you foresee it causing any problems under the hood?

Hugh

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Tue 22 Mar 2016 - 22:59:09 EDT

This archive was generated by hypermail 2.2.0 : Wed 23 Mar 2016 - 06:27:52 EDT