Permalink
Browse files

keyboard support

  • Loading branch information...
Steve Howell
Steve Howell committed Jan 30, 2012
1 parent 76b18e5 commit dc36427d50ed942e7eecdd1840cda0c74076fbc6
Showing with 32 additions and 2 deletions.
  1. +30 −1 assets/view_file.coffee
  2. +2 −1 side_by_side.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()
@@ -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>"

0 comments on commit dc36427

Please sign in to comment.