Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

keyboard support

  • Loading branch information...
commit dc36427d50ed942e7eecdd1840cda0c74076fbc6 1 parent 76b18e5
Steve Howell authored
Showing with 32 additions and 2 deletions.
  1. +30 −1 assets/view_file.coffee
  2. +2 −1  side_by_side.coffee
View
31 assets/view_file.coffee
@@ -19,4 +19,33 @@ $ ->
# In some editors, like TextMate, files get saved when you remove
# focus from the editor, so we give a couple seconds for the save
# to happen and for coffee -wc to wake up.
- setTimeout f, 2000
+ setTimeout f, 2000
+
+ set_up_key_mappings = ->
+ digits = ''
+
+ go_to_js_line = (digits) ->
+ id = "js_#{digits}"
+ elem = $ "a##{id}"
+ if elem.length == 1
+ elem.focus()
+ true
+ else
+ alert "JS line number #{digits} does not exist"
+ false
+
+ document.onkeypress = (e) ->
+ keyunicode = e.charCode or e.keyCode
+ c = String.fromCharCode(keyunicode)
+ if '0' <= c <= '9'
+ digits += c
+ found = go_to_js_line digits
+ if not found then digits = ''
+ true
+ else if c is ' '
+ digits = ''
+ false
+ else
+ false
+
+ set_up_key_mappings()
View
3  side_by_side.coffee
@@ -29,7 +29,8 @@ exports.side_by_side = (matches, source_lines, dest_lines) ->
line_numbers = (start, end, prefix) ->
line_number = (ln) ->
- """<a name="#{prefix}_#{ln}"><a href="##{prefix}_#{ln}">#{prefix}:#{ln}</a>"""
+ id = "#{prefix}_#{ln}"
+ """<a name="#{id}"><a id="#{id}" href="##{id}">#{prefix}:#{ln}</a>"""
numbers = (line_number(ln+1) for ln in [start...end])
"<pre class='numbers'>#{numbers.join('\n')}</pre>"
Please sign in to comment.
Something went wrong with that request. Please try again.