diff --git a/app/dependencies.rb b/app/dependencies.rb index bc290eac..0f92eb8e 100644 --- a/app/dependencies.rb +++ b/app/dependencies.rb @@ -6,3 +6,4 @@ require 'browser/http' require 'browser/location' require 'browser/history' +require 'browser/navigator' \ No newline at end of file diff --git a/app/helper.rb b/app/helper.rb new file mode 100644 index 00000000..e295824d --- /dev/null +++ b/app/helper.rb @@ -0,0 +1,13 @@ +require 'dependencies' + +class Helper + @@navigator = $window&.navigator + + def self.ios? + @@navigator.user_agent&.match?(/\b(iPad|iPhone|iPod)\b/) || false + end + + def self.macos? + @@navigator.user_agent&.match?(/\bMac\b/) || false + end +end diff --git a/app/try_ruby.rb b/app/try_ruby.rb index 81ad5a9a..2cf7f63c 100644 --- a/app/try_ruby.rb +++ b/app/try_ruby.rb @@ -4,6 +4,7 @@ require 'editor' require 'lesson' require 'ruby_engine' +require 'helper' # The TryRuby application class TryRuby @@ -61,7 +62,8 @@ def initialize #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.ctrl? && !Helper.ios?) || ((Helper.macos? || Helper.ios?) && e.meta?)) && e.key == "Enter" + e.prevent do_run end end