Re: [code] [textadept] The UPDATE_UI event

From: Mitchell <m.att.foicica.com>
Date: Wed, 23 Mar 2016 08:39:41 -0400 (EDT)

Hi Hugh,

On Wed, 23 Mar 2016, Hugh Low wrote:

> 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:

By default, Textadept has `buffer.idle_styling` set to something other
than NONE. So unless you turned it off explicitly (likely via
~/.textadept/properties.lua), Textadept will do syntax highlighting in the
background, and that operation emits UPDATE_UI events (with a mask of 1).
If you turn off idle styling, I think you'll see only one event per
addition/deletion. (I only saw one event at a time on text files with no
syntax highlighting.)

> [snip]
>
> 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?

I cannot forsee any problems with this, but that doesn't mean there aren't
any :)

Cheers,
Mitchell

-- 
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 Wed 23 Mar 2016 - 08:39:41 EDT

This archive was generated by hypermail 2.2.0 : Thu 24 Mar 2016 - 06:50:53 EDT