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

Remove leading dollar signs when copying codeblocks #50

Merged
merged 12 commits into from
Jun 2, 2023

Conversation

andermi
Copy link
Collaborator

@andermi andermi commented Apr 26, 2023

Just a bit of javascript hackery!

Works when "triple-clicking" and also clicking on the copy button for clode blocks.
NOTE: it doesn't limit selection of the dollar signs; it just doesn't copy them

e.g.
selected text: (or contents of code block)

$ mkdir -p ~/controller_ws/src
$ cd ~/controller_ws/src

pasted text:

mkdir -p ~/controller_ws/src
cd ~/controller_ws/src

andermi added 2 commits April 26, 2023 11:26
Signed-off-by: Michael Anderson <anderson@mbari.org>
Signed-off-by: Michael Anderson <anderson@mbari.org>
@andermi andermi requested a review from hamilton8415 April 26, 2023 21:22
@github-actions
Copy link

github-actions bot commented Apr 26, 2023

PR Preview Action v1.4.4
Preview removed because the pull request was closed.
2023-06-02 05:33 UTC

@andermi
Copy link
Collaborator Author

andermi commented May 9, 2023

Since most browsers (other than Firefox) don't allow multiple (non-contiguous) selection ranges, this is the best I can do without getting into some serious hacking to rewrite the codeblocks to place the $ in their own table entry. The problem is that if they select multiple lines with $ on each line, it will modify the selection to only the first line (and correctly without the dollar sign) but still copy both lines (correctly without dollar sign)

@andermi
Copy link
Collaborator Author

andermi commented May 9, 2023

So, to the user it looks as if it only copied the first line, but in fact copied both lines... should I change it to actually copy only what is selected even if they initially selected multiple?

@andermi
Copy link
Collaborator Author

andermi commented May 9, 2023

also, I need someone to test on Safari I suppose...

Signed-off-by: Michael Anderson <anderson@mbari.org>
@hamilton8415
Copy link
Collaborator

Yeah, probably best to only copy what's highlighted, minus the dollar sign of course... I can check on Safari on my mac...

@andermi
Copy link
Collaborator Author

andermi commented May 9, 2023

ok, fixed to only copy what's highlighted (after copy event modifies selection)

andermi added 2 commits May 9, 2023 12:28
Signed-off-by: Michael Anderson <anderson@mbari.org>
Signed-off-by: Michael Anderson <anderson@mbari.org>
@andermi
Copy link
Collaborator Author

andermi commented May 12, 2023

Don't know if this counts, but I tried it in Safari on my iPhone and it works!

@hamilton8415
Copy link
Collaborator

Totally counts.

Copy link
Collaborator

@hamilton8415 hamilton8415 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this

@mabelzhang
Copy link
Collaborator

mabelzhang commented May 22, 2023

Can merge as is, but there is a weird behavior if I highlight and copy multiple lines, e.g.
https://osrf.github.io/mbari_wec/pr-preview/pr-50/Tutorials/Simulation/SimulatorInteractionPbcmd/#example-usage

empy -D 'inc_wave_spectrum_type="None"' -o ~/mbari_wec_ws/install/buoy_description/share/buoy_description/models/mbari_wec/model.sdf ~/mbari_wec_ws/install/buoy_description/share/buoy_description/models/mbari_wec/model.sdf.em

ros2 launch buoy_gazebo mbari_wec.launch.py regenerate_models:=false

The copy button works. But if I highlight both lines and then Ctrl+C, the result is weird - the highlight changes to first line only, and only the first line is copied.

This could be a new issue to be addressed in the future. Or if this complicates things, feel free to revert to your previous version that worked better.

@andermi
Copy link
Collaborator Author

andermi commented Jun 2, 2023

@mabelzhang See these comments. That behavior is working as intended although not ideal...

#50 (comment)

#50 (comment)

#50 (comment)

The issue is that none of the browsers allow non-contiguous selection regions (i.e. two lines with a dollar sign in the middle).
I can certainly copy and remove the dollar signs programmatically but the selection buffer doesn't reflect what's copied that way...

@andermi andermi merged commit 52401e0 into main Jun 2, 2023
@andermi andermi deleted the andermi/copy_codeblocks branch June 2, 2023 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants