geany / geany-osx

Things needed to bundle Geany for OSX
Other
24 stars 14 forks source link

Block pasting/Column mode editing doesnt work properly #40

Closed Matusus closed 1 year ago

Matusus commented 1 year ago

Hello, I have macOS 12.6 and geany "installed" in version 1.38. Plugins enabled Auto-mark, Extra selection, Macros.

Copying of selected blocks in the text seems to be working fine, but I'm facing issues during pasting of selected block into/behind the text. I used to per my windows and Linux from past some chain by the end of line behind text, but for now if I paste it an event with block selection it pastes all lines and includes by each line "enter"/end of line.

Example

lines: 1 2 3

I want put behind following chain: aaa bbb ccc

expected result: aaa 1 bbb 2 ccc 3

current result: aaa 1 2 3 bbb ccc

Thank you for the advice/hints BR Honza

elextr commented 1 year ago

It looks like you don't have a rectangular selection, just a regular selection. Did you <ctrl><shift>click not <shift>click?

Matusus commented 1 year ago

Hello, I selecting section by ctrl shift and then I pasting by command v so it should be a correct rectangular selection.

BR Honza

elextr commented 1 year ago

WFM

16:08:22: Geany INFO        : Geany 1.39 (git >= 563d94d85), unknown
16:08:22: Geany INFO        : GTK 3.24.20, GLib 2.64.6
16:08:22: Geany INFO        : OS: Linux Mint 20 (ulyana)

As you said it works on Windows and Linux, maybe its a mac thing, moving issue to geany-osx

techee commented 1 year ago

This is a duplicate of https://github.com/geany/geany/issues/2685. Unfortunately I don't know how this could be fixed so the paste works also outside Geany.

elextr commented 1 year ago

Possibly Scintilla should define a new clipboard target type (eg "SCINTILLARECTANGLE") and advertise that as being available when a rectangular selection is made as well as the normal "TEXT", then when pasting, Scintilla can accept that target preferentially if its available, so Scintilla will then know its a rectangular paste. Probably would even work between two scintillas in different apps (maybe).

Just needs "somebody" to do it ;-P

techee commented 1 year ago

Well, I'm not sure if I understand correctly but the block-copy information should be stored together with the copied text to the clipboard and not just be remembered by Scintilla. Imagine this situation:

  1. User block-copies text in Geany (and Scintilla remembers it did a block copy)
  2. User switches to another (non-Scintilla) application and copies some other text from it
  3. User returns back to Geany and performs a paste. Scintilla remembers it did a block copy in (1) and will paste this text in the block mode even though the clipboard contains something else now
elextr commented 1 year ago

User switches to another (non-Scintilla) application and copies some other text from it User returns back to Geany and performs a paste. Scintilla remembers it did a block copy in (1) and will paste this text in the block mode even though the clipboard contains something else now

No it won't, the other application advertising new clipboard contents won't offer the "SCINTILLARECTANGLE" target (unless its another Scintilla which copied in rectangle mode), so Scintilla won't paste as a rectangle.

PS "target" is a GTK name for "data format", why they can't just call it that I don't know, maybe an X11 thing from the mists of time.

techee commented 1 year ago

No it won't, the other application advertising new clipboard contents won't offer the "SCINTILLARECTANGLE" target (unless its another Scintilla which copied in rectangle mode), so Scintilla won't paste as a rectangle.

OK, I didn't know this "target" thing.

PS "target" is a GTK name for "data format", why they can't just call it that I don't know, maybe an X11 thing from the mists of time.

Is it documented somewhere how to define and use these "targets" and how this whole thing works?

elextr commented 1 year ago

I'm not aware of any clean description, but better googlers may prove me wrong.

Its all based around the way X11 did "clipboards" (without ever actually having such a thing):

  1. user selects in app1 which tells X11 'I got a selection and can provide it in "foo", "bar", and "bletch" formats'
  2. user pastes in app2 which asks X11 'got a selection guv?'
  3. X11 replies to app2, 'sure, "foo" or "bar" or "bletch"?'
  4. app2 asks X11 for '"foo" please'
  5. X11 tells app1 "your finest selection in "foo" my good man, and don't spare the bits'[^1]
  6. app1 splurts the data in "foo" format to X11 which forwards it to app2
  7. app2 does paste

The data is never copied to a "clipboard". If you look at the GTK clipboard API you can see how it maps to this, where "foo", "bar", and "bletch" are called targets and are represented as GDKAtoms (I suspect another hangover from X11 from the days when strings were always thought of as sloooow and sending and comparing integers was considered a good idea).

IIRC X11 had predefined atoms for "STRING", "PIXMAP" etc, but its always possible to define more, see the GDKAtom interface.

Wayland works like X11 except it recommends using Mime types for "foo" etc, but in the end they are all just strings that have been atomised, "application/scintilla.block_select" is also suitable.

How this is simulated on top of the platform clipboards for Windows and Macos I am not sure since I don't know how they work.

[^1]: not sure why X11 has a toffee english accent :grin:

elextr commented 1 year ago

How this is simulated on top of the platform clipboards for Windows and Macos I am not sure since I don't know how they work.

Well whatdya know ... https://github.com/mirror/scintilla/blob/a6d738543a0efd2d2ee3e985ab26c83eecbbd1a0/win32/ScintillaWin.cxx#L467

[Edit: in case its not clear, it appears that Scintilla on Windows does pretty much exactly as suggested, defining its own clipboard format for block selects]

Matusus commented 1 year ago

Make it clear regarding rectangle copy/paste I would still use it only in Geany. Not over multiple applications. I would believe that over multiple apps in MAC OS could be an issue... But only the first part of the string is copied from the terminal and then all modifications including block copy paste are in the same list...

techee commented 1 year ago

Make it clear regarding rectangle copy/paste I would still use it only in Geany. Not over multiple applications. I would believe that over multiple apps in MAC OS could be an issue... But only the first part of the string is copied from the terminal and then all modifications including block copy paste are in the same list...

The trouble is that using a different character like \1 to indicate block copy introduces side effects and I don't think Neil (the maintainer of Scintilla) would accept such a fix.

elextr commented 1 year ago

The trouble is that using a different character like \1 to indicate block copy introduces side effects and I don't think Neil (the maintainer of Scintilla) would accept such a fix.

There is technically no guarantee that another app would ignore the \0 either, it might not be written in C and so it might try to use it. The indication must not be part of a "text" format clipboard format that other apps see, thats why Windows makes its own format for block select as above. The Scintilla GTK backend should do the same on all platforms. Currently it actually uses the same Windows code as a special case on PLAT_GTK_WIN, perhaps that special case could be removed if it was done for all GTK. Because its a separate format, only another Scintilla will ask for it, all other apps will ignore that format and ask for text, so there will be no issues with extra characters.

elextr commented 1 year ago

Currently it actually uses the same Windows code as a special case on PLAT_GTK_WIN

The fact that it needs to do this special case probably says that Windows lops off the \0 as well ;-)

Syntonica commented 1 year ago

As far as I can see, block-copied text just sits on the clipboard as plain text with \n at the end of each line. If I open Eclipse and paste the text, it is pasted normally. If I put Eclipse into its own block copy mode, the text is pasted as you would expect. I don't think a special flavor of text is really required, just that the receiver is expecting to paste text as a block.

techee commented 1 year ago

As far as I can see, block-copied text just sits on the clipboard as plain text with \n at the end of each line.

Nope. As explained here

https://github.com/geany/geany-osx/issues/40#issuecomment-1267472339

the block-copied text also needs to contain the information it was block-copied in the clipboard, otherwise pasting might not work correctly in all situations.

Syntonica commented 1 year ago

As far as I can see, block-copied text just sits on the clipboard as plain text with \n at the end of each line.

Nope. As explained here

#40 (comment)

the block-copied text also needs to contain the information it was block-copied in the clipboard, otherwise pasting might not work correctly in all situations.

I don't think a special clipboard format should be required, just that Geany can be put into a block-paste mode the same as using puts it into block-copy mode. The benefit of this is that I can go to Notepad and copy out my shopping list in plain text and then paste it as a block elsewhere. If I wanted to.

elextr commented 1 year ago

How is Scintilla put in "block paste mode"? The user just presses ctrl+v and the paste happens, there is nothing the user does to indicate "block paste mode".

techee commented 1 year ago

I've just made the following builds:

Geany 1.38 built with the latest GTK and other dependencies, including some extra fixes which I plan to release as the official macOS build on the Downloads page unless there are some problems with it: https://download.geany.org/snapshots/geany-1.38_osx-5.dmg https://download.geany.org/snapshots/geany-1.38_osx_arm64-2.dmg

Like the above but Geany and plugins are from current git master: https://download.geany.org/snapshots/geany-1.38_osx.dmg https://download.geany.org/snapshots/geany-1.38_osx_arm64.dmg

I decided to "fix" this by trading one bug for another. Instead of the \0 in the copy/pasted text that indicates block copy I use \1 which is preserved by macOS. This will include the \1 when the block-copied text is pasted outside Geany but I don't think people commonly use block-copy to paste it to other applications (it doesn't work as a block-copy in this case anyway).

I just created a simple patch doing this on top of Geany sources that is applied automatically during macOS binary build - it's really just an ugly workaround which I don't want to submit upstream.