Skip to content

Commit 85a532e

Browse files
authored
Merge pull request #187 from liberaldev/fix-apple-device
Improved behavior of the run shortcut key (ctrl+return (ctrl+enter)) on Apple devices
2 parents c52f2ec + 629a48f commit 85a532e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

app/dependencies.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
require 'browser/http'
77
require 'browser/location'
88
require 'browser/history'
9+
require 'browser/navigator'

app/helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'dependencies'
2+
3+
class Helper
4+
@@navigator = $window&.navigator
5+
6+
def self.ios?
7+
@@navigator.user_agent&.match?(/\b(iPad|iPhone|iPod)\b/) || false
8+
end
9+
10+
def self.macos?
11+
@@navigator.user_agent&.match?(/\bMac\b/) || false
12+
end
13+
end

app/try_ruby.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'editor'
55
require 'lesson'
66
require 'ruby_engine'
7+
require 'helper'
78

89
# The TryRuby application
910
class TryRuby
@@ -61,7 +62,8 @@ def initialize
6162

6263
#If hold down the control and the Enter key goes down, run
6364
$document.on :keydown, '#editor' do |e|
64-
if e.key == "Enter" && e.ctrl?
65+
if ((e.ctrl? && !Helper.ios?) || ((Helper.macos? || Helper.ios?) && e.meta?)) && e.key == "Enter"
66+
e.prevent
6567
do_run
6668
end
6769
end

0 commit comments

Comments
 (0)