Improved behavior of the run shortcut key (ctrl+return (ctrl+enter)) on Apple devices#187
Merged
hmdne merged 11 commits intoruby:masterfrom Dec 6, 2024
Merged
Improved behavior of the run shortcut key (ctrl+return (ctrl+enter)) on Apple devices#187hmdne merged 11 commits intoruby:masterfrom
hmdne merged 11 commits intoruby:masterfrom
Conversation
hmdne
reviewed
Dec 5, 2024
app/try_ruby.rb
Outdated
| #If hold down the control and the Enter key goes down, run | ||
| $document.on :keydown, '#editor' do |e| | ||
| if e.key == "Enter" && e.ctrl? | ||
| if e.key == "Enter" && ((e.ctrl? && !@navigator.user_agent&.match?(/\b(iPad|iPhone|iPod)\b/)) || |
Collaborator
There was a problem hiding this comment.
This is kinda hard to read... maybe we could add helper functions like:
def ios?
@navigator.user_agent&.match?(/\b(iPad|iPhone|iPod)\b/)
end
def macos?
@navigator.user_agent&.match?(/\bMac\b/)
endThen the modified code could be just:
$document.on :keydown, '#editor' do |e|
if e.key == "Enter" && ((!ios? && e.ctrl?) || ((ios? || macos?) && e.meta?))
e.prevent
do_run
end
end
Contributor
Author
There was a problem hiding this comment.
I added the Helper class to make my code more reusable
hmdne
reviewed
Dec 6, 2024
app/try_ruby.rb
Outdated
| #If hold down the control and the Enter key goes down, run | ||
| $document.on :keydown, '#editor' do |e| | ||
| if e.key == "Enter" && e.ctrl? | ||
| if (e.key == "Enter" && (e.ctrl? && !Helper.ios?)) || ((Helper.macos? || Helper.ios?) && e.meta?) |
Collaborator
There was a problem hiding this comment.
Right-hand side of the || expression is missing check for Enter.
Contributor
Author
There was a problem hiding this comment.
Thank you for pointing this out. I've fixed the issue, please check it out.
Collaborator
|
Looks good to me :D Let's merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At the time I posted #183, I didn't have a Mac or other Apple device, so I couldn't validate the issue with Apple devices. I have now purchased a Mac and verified the issue that occurs on Apple devices, and this PR improves the run shortcut to work well on Apple devices. The detailed improvements are as follows: