Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy button double-spaces highlighted lines in documented code samples #1489

Open
alderven opened this issue Feb 1, 2023 · 11 comments
Open

Comments

@alderven
Copy link

alderven commented Feb 1, 2023

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
@pvcraven
Copy link
Member

pvcraven commented Feb 1, 2023

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.

@alderven
Copy link
Author

alderven commented Feb 1, 2023

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.

@einarf
Copy link
Member

einarf commented Feb 2, 2023

Proably gets mangled in the copy. Safer expression is

        self.tank.position = (
            self.tank.center_x + x_dir,
            self.tank.center_y + y_dir,
        )

@pushfoo
Copy link
Member

pushfoo commented Feb 2, 2023

Could we update the example on dev branch with the following?

  1. texture rotation on load using the new coordinate flip features
  2. 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.

@alderven alderven changed the title "Sprite Rotation Around a Tank" example: SyntaxError Extra spaces when copying code from "Sprite Rotation Around a Tank" example Feb 2, 2023
@alderven
Copy link
Author

alderven commented Feb 2, 2023

Proably gets mangled in the copy

yes, I've updated issue description accordingly

@pushfoo
Copy link
Member

pushfoo commented Feb 2, 2023

@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:

I suspect it affects all versions, but I can't verify the dev branch because its CSS appears to be broken at the moment:
image

Steps to replicate for doc versions hosted on api.arcade.academy:

  1. Select an arcade doc version between 2.5.7 and 2.6.17
  2. Open any page containing at least 1 code box which has both a copy button and highlighted lines
  3. Do not select any text directly
  4. Click the copy button at the top right of the code box
  5. Paste the clipboard contents into an external plain text context
  6. Any lines highlighted in the source will have doubled spaces in the destination

@pushfoo
Copy link
Member

pushfoo commented Feb 2, 2023

This seems to be a broken interaction between these two sphinx plugins:

arcade/doc/conf.py

Lines 53 to 54 in 102c27f

'sphinx.ext.viewcode',
'sphinx_copybutton',

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.

@pushfoo
Copy link
Member

pushfoo commented Feb 2, 2023

@alderven Could you please verify the following temporary workarounds?

Only the highlighted section

  1. Select a highlighted text segment manually
  2. Copy via hotkey or right-click context menu
  3. Paste into the destination

The entire code block

  1. Select the first line in the code block manually
  2. If needed, scroll down to the end of the code block (the pgdown key may be helpful)
  3. Hold down shift
  4. Click inside the code box immediately to the right of the end of the last line
  5. The entire code block should now be highlighted
  6. Release shift
  7. Copy via hotkey or right-click context menu
  8. Paste into the destination

@alderven
Copy link
Author

alderven commented Feb 2, 2023

@alderven Could you please verify the following temporary workarounds?

thanks @pushfoo both workarounds are working

@pushfoo
Copy link
Member

pushfoo commented Feb 9, 2023

tl;dr:

  1. This is a known issue with sphinx-copybutton
  2. Frontend help would be appreciated
  3. 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.

@pushfoo
Copy link
Member

pushfoo commented Feb 10, 2023

@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.

@pvcraven pvcraven changed the title Extra spaces when copying code from "Sprite Rotation Around a Tank" example Copy button double-spaces highlighted lines in documented code samples Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants