arcade
arcade copied to clipboard
Copy button double-spaces highlighted lines in documented code samples
Steps to reproduce:
Copy code from following example: Sprite Rotation Around a Tank
Extra lines added to copied text. E.g.
self.tank.position =\
self.tank.center_x + x_dir,\
self.tank.center_y + y_dir
should be:
self.tank.position =\
self.tank.center_x + x_dir,\
self.tank.center_y + y_dir
If you type in 'pip freeze' can you confirm you have 'pyglet==2.0.dev23'?
Running 2.6.17 I'm not able to reproduce.
Line 155 is a comment too, make sure the code wasn't accidentally modified.
If you type in 'pip freeze' can you confirm you have 'pyglet==2.0.dev23'?
Yes, that's correct.
Line 155 is a comment too, make sure the code wasn't accidentally modified.
When I press Copy to clipboard
button and then paste copied code it added extra empty lines between lines of code. Like this:
self.tank.position =\
self.tank.center_x + x_dir,\
self.tank.center_y + y_dir
I don't see such issue on other examples. Probably something wrong with the code formatting on that specific case.
Proably gets mangled in the copy. Safer expression is
self.tank.position = (
self.tank.center_x + x_dir,
self.tank.center_y + y_dir,
)
Could we update the example on dev branch with the following?
- texture rotation on load using the new coordinate flip features
- pyglet vectors rather than risking errors from position arithmetic the long way
The end result would be more resistant to copy and paste problems and should still be compatible with setting self.tank.position
.
Proably gets mangled in the copy
yes, I've updated issue description accordingly
@pvcraven @einarf tl;dr using a plugin-created copy button instead of copying a direct selection results in duplicated newlines on all lines which were highlighted inside the code block
I'm running Chromium under Debian, and have verified it on the following pages for 2.5.7, 2.6.0, and latest (2.6.17) on api.arcade.academy
:
- Part 2 of the simple platformer tutorial
- Part 3 of the simple platformer tutorial
- The sprite_move_animation example
I suspect it affects all versions, but I can't verify the dev branch because its CSS appears to be broken at the moment:
Steps to replicate for doc versions hosted on api.arcade.academy
:
- Select an arcade doc version between 2.5.7 and 2.6.17
- Open any page containing at least 1 code box which has both a copy button and highlighted lines
- Do not select any text directly
- Click the copy button at the top right of the code box
- Paste the clipboard contents into an external plain text context
- Any lines highlighted in the source will have doubled spaces in the destination
This seems to be a broken interaction between these two sphinx plugins: https://github.com/pythonarcade/arcade/blob/102c27f292bb9e8ca9490848cddeace27c0afa3e/doc/conf.py#L53-L54
The doc for sphinx_copybutton
indicates there is a way to use CSS selectors to exclude matching text. I think this is the likeliest solution. Unfortunately, I need to head off for the moment, but I can try to implement this later if nobody else beats me to it.
@alderven Could you please verify the following temporary workarounds?
Only the highlighted section
- Select a highlighted text segment manually
- Copy via hotkey or right-click context menu
- Paste into the destination
The entire code block
- Select the first line in the code block manually
- If needed, scroll down to the end of the code block (the pgdown key may be helpful)
- Hold down shift
- Click inside the code box immediately to the right of the end of the last line
- The entire code block should now be highlighted
- Release shift
- Copy via hotkey or right-click context menu
- Paste into the destination
@alderven Could you please verify the following temporary workarounds?
thanks @pushfoo both workarounds are working
tl;dr:
- This is a known issue with sphinx-copybutton
- Frontend help would be appreciated
- Parsing the highlighted source DOM in JS would be ugly, but it could work
The plugin's exclusion selector argument might not work here. To my understanding, parent selectors will exclude the highlighted line the same way excluding .hll
would. Maybe there's a clever way to use psuedo-elements like ::after
or a stylesheet tweak to solve this, but I haven't found one yet. Assistance from someone with strong frontend expertise would be appreciated.
Parsing the DOM in JS could work, but it's ugly and seems wasteful even if we cache the result.
@pvcraven @einarf tl;dr I think this fixed in dev / 2.7
I can't replicate this in a clean local venv on the tip of development. 2.6.17
appears to exhibit it, but I haven't been able to narrow down the exact changes which eliminate it with enough certainty for a backport to 2.6.X.
If any of this is still relevant it will be fixed in https://github.com/pythonarcade/arcade/issues/2243