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

From: Danny MacMillan <foicica.att.nekulturny.org>
Date: Sun, 22 Oct 2017 14:24:01 -0600

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.
>
> Something like the proposal here
>
> https://github.com/jaap-karssenberg/zim-desktop-wiki/issues/29#issuecomment-309574981
>
> keys.cc = function()
> -- get selection
> local sel = buffer.get_sel_text()
> buffer.copy()
> if sel ~= ui.clipboard_text then
> -- alert for debugging (retry, if not the same ...)
> ui.dialogs.msgbox({text="Clipboard problem ...")
> end
> end
>
> Could be applied to Textadept if that would fix it. Maybe wrapping the
> retries with some timeout and limit ...

Thanks for the idea.

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.

/** `ui.__index` Lua metamethod. */
static int lui__index(lua_State *L) {
   const char *key = lua_tostring(L, 2);
   if (strcmp(key, "clipboard_text") == 0) {
#if GTK
     char *text = gtk_clipboard_wait_for_text(
                  gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
     lua_pushstring(L, text ? text : "");
     if (text) free(text);
#elif CURSES

-- 
Dan
-- 
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 Sun 22 Oct 2017 - 16:24:01 EDT

This archive was generated by hypermail 2.2.0 : Mon 23 Oct 2017 - 06:42:20 EDT