Re: [code] ctrl-c frequently doesn't work on Windows.

From: Mitchell <m.att.foicica.com>
Date: Tue, 24 Oct 2017 11:09:36 -0400 (EDT)

Hi Danny,

On Sun, 22 Oct 2017, Danny MacMillan wrote:

> On 2017-10-22 14:24, Danny MacMillan wrote:
>> On 2017-10-22 13:28, Robert Gieseke wrote:
>>> But, I think you might be able to wrap Textadept's copy function in Lua
>>> to check if it has actually been copied.
>>>
>> This is ham-fisted I know but I put this (and only this) in my init.lua:
>>
>> keys.cc = function()
>> -- get selection
>> local sel = buffer.get_sel_text()
>> buffer.copy()
>> ui.bufstatusbar_text = ui.clipboard_text
>> if sel ~= ui.clipboard_text then
>> -- alert for debugging (retry, if not the same ...)
>> ui.statusbar_text = "Clipboard problem ..."
>> else
>> ui.statusbar_text = "Clipboard just fine ..."
>> end
>> end
>>
>> So every time I ctrl-c, the left side of the status bar will show
>> either "Clipboard problem ..." or "Clipboard just fine ..." and the
>> right side will show the contents of the clipboard after the copy
>> operation.
>>
>> Unfortunately even in the failure case (when the text I copied can't
>> be pasted into other Windows applications), it prints "Clipboard just
>> fine ..." on the left, and the text I tried to copy on the right. I
>> take this to mean that ui.clipboard_text isn't actually reading the
>> clipboard, but some cache. I'm far from a C expert but this chunk of
>> code in textadept.c makes me think the cache must be inside GTK. So
>> I'm back to square 1.

Yes, GTK clipboard operations are asynchronous, so if you ask for text too quickly after copying it, you'll get the "previous" contents.

> On the hypothesis that it's a race condition causing this issue, I put this
> in init.lua.
>
> -- busy-waiting is terrible but I couldn't find a ready-to-use sleep
> function
> -- This implementation is taken from here
> http://lua-users.org/wiki/SleepFunction
> function sleep(s)
> local ntime = os.clock() + s
> repeat until os.clock() > ntime
> end
>
> keys.cc = function()
> buffer.copy()
> sleep(0.1)
> end
>
> With this in my init.lua, I haven't (yet) had a clipboard issue.

Robert suggested `timeout()` in a follow-up, and I'd suggest putting your clipboard check in the timeout. Something like:

   keys.cc = function()
     local expected = buffer:get_sel_text()
     buffer:copy()
     timeout(0.1, function()
       if expected == ui.clipboard_text then
         ui.statusbar_text = 'Worked!' -- for debugging
       else
         ui.statusbar_text = 'Failed!' -- for debugging
         buffer:copy_text(expected)
         return false -- try again
       end
     end)
   end

Now I apologize if I misunderstood the problem in this thread and you've already tried something similar. (I confess it's a bit over my head.)

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 Tue 24 Oct 2017 - 11:09:36 EDT

This archive was generated by hypermail 2.2.0 : Wed 25 Oct 2017 - 06:34:39 EDT