Re: [code] [textadept] Working with clipboard

From: Mitchell <>
Date: Sun, 15 Sep 2019 15:35:04 -0400 (EDT)

Hi Qwerky,

On Sun, 15 Sep 2019, Qwerky wrote:

> Hi Mitchell,
> On 2019-09-15 09:08, Mitchell wrote:
>> Hi Qwerky,
>> On Sat, 14 Sep 2019, Qwerky wrote:
>>> Hi Mitchell,
>>> What is needed to make use of buffer.copy_text(), to write text to the
>>> clipboard?  I've used `cliptext = ui.clipboard_text` to read the clipboard
>>> text to a string, and then `for line in cliptext:gmatch('.-\n') do` to
>>> read
>>> the lines of text from the string into a table.
>>> After that, `cliptext = table.concat(cliplines, '\n')` to join the table
>>> lines, and `buffer.copy_text(cliptext)` to write that string back to the
>>> clipboard.
>>> Although this text looks the same on the clipboard, when it is pasted into
>>> some other text, the result is not the same as pasting the original
>>> clipboard
>>> text into some other text.  Specifically, when the original text is
>>> rectangular, and is pasted into some other text, it pastes each line into
>>> succeeding lines of the other text.  But after the above operation, the
>>> text
>>> is pasted as a group of lines at a single place, rather than individual
>>> lines
>>> going into succeeding lines of the receiving text.
>>> How can I keep the text rectangular after writing it back to the
>>> clipboard?
>> This is not possible with Scintilla, unfortunately. You cannot put
>> rectangular or multi-selected text on the clipboard. Only Scintilla can do
>> it. It's like a one-way thing.
>> Cheers,
>> Mitchell
> Hmm... blocked at every turn.  But wait, I'm not sure that the problem lies
> with putting the text on the clipboard, but rather with /reading it back/ in
> a rectangular format (see my earlier follow-up to this thread, about
> `buffer.selection_is_rectangle`).  I'll quote it here:
> "My working theory is that `buffer.selection_is_rectangle`, which is
> read-only, is used to keep track of whether or not the selection is
> rectangular, and controls how the text is pasted.  And further, that it is
> being reset by `buffer.copy_text()`, so that even though the text was
> originally selected as rectangular, after using `buffer.copy_text()`, it will
> always be pasted as stream.  Since `buffer.selection_is_rectangle` is
> read-only, I'm not sure how to work around this.  Does this theory sound
> correct?"
> When I modify the clipboard text in a Lua module, as described above, and
> then paste it into text in a different text editor, it can be made to appear
> correctly (depends on the text editor, and upon its settings).  It seems to
> me that Scintilla is keeping track of the clipboard contents, and will paste
> back as rectangular only when it believes it has put rectangular data there.
> Also, I think it must be monitoring the clipboard, and becomes aware when
> another application places something on the clipboard, in which case it won't
> paste back as rectangular (or as line), but only as stream.
> So whether the limitation is in writing or reading the clipboard, the end
> result (and perhaps the answer as well) may be the same:  Scintilla won't
> allow it!

Think about it for a minute: clipboard text is just a sequence of bytes to pass between applications. It is up to the applications how they want to interpret it. Scintilla doesn't try to do anything fancy. Its documentation states how it outputs rectangular selections and multiple selections on the clipboard. It is then up to clients or external applications to figure out what to do with it.

The same idea applies to incoming clipboard text. Just because there is a rectangular or multiple selection in play when text is pasted doesn't mean Scintilla should try and be "smart" about what to do with said text. Incoming text with newlines could legitimately not be a rectangular selection, even if there is one currently.

> This is a real blow, as this issue with rectangular selections is the last
> major obstacle that I have with Scintilla.  And just when I thought I had a
> solution (by padding the rectangle in a module), it is blocked again.

You could try writing your own Lua code that interprets your clipboard text in a special way, determines rectangular selection bounds, and then pastes as you expect. I think this is kind of what Scintilla expects client applications to do, as clipboard formats are not standardized, as I alluded to above.

> Well, I've posted on the Scintilla list, and we'll see what Neil says about
> it in October, when he gets back.  If there are any other Textadept users who
> would like this feature, you may wish to add your voice as well.
> Thanks for you help, Mitchell.  Hopefully a solution will arrive.
> Oh, a thought just came up: `buffer.selection_is_rectangle` is read-only in
> Textadept (and presumably so is its counterpart in Scintilla).  Would you be
> able to make it read/write, which may help?

Making it writable will not help. Scintilla just does not interpret text put on the clipboard for a reason.


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sun 15 Sep 2019 - 15:35:04 EDT

This archive was generated by hypermail 2.2.0 : Mon 16 Sep 2019 - 06:46:53 EDT