Skip to content

Commit

Permalink
refactoring: <down> and <tab> in editors are commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ngn committed Apr 1, 2015
1 parent 8dfeb93 commit aa54f22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
32 changes: 16 additions & 16 deletions client/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,7 @@ module.exports = (e, opts) -> # opts contains callbacks to ide.coffee
keyMap: 'dyalog', matchBrackets: true, autoCloseBrackets: {pairs: '()[]{}', explode: '{}'}
gutters: ['breakpoints', 'CodeMirror-linenumbers'], indentUnit: 4
extraKeys:
'Shift-Tab': 'indentLess'
Tab: ->
if cm.somethingSelected()
cm.execCommand 'indentMore'
else
c = cm.getCursor(); s = cm.getLine c.line
if /^ *$/.test s[...c.ch]
cm.execCommand 'indentMore'
else
emit 'Autocomplete', line: s, pos: c.ch, token: id
return
Down: ->
l = cm.getCursor().line
if l != cm.lineCount() - 1 || /^\s*$/.test cm.getLine l then cm.execCommand 'goLineDown'
else cm.execCommand 'goDocEnd'; cm.execCommand 'newlineAndIndent'; xline = l + 1
return
'Shift-Tab': 'indentLess', Tab: 'tabOrAutocomplete', Down: 'downOrXline'

cm.on 'cursorActivity', ->
if xline != null
Expand Down Expand Up @@ -178,6 +163,21 @@ module.exports = (e, opts) -> # opts contains callbacks to ide.coffee
if isDebugger
emit 'SetLineAttributes', win: id, nLines: cm.lineCount(), lineAttributes: stop: breakpoints[..].sort (x, y) -> x - y
return
tabOrAutocomplete: ->
if cm.somethingSelected()
cm.execCommand 'indentMore'
else
c = cm.getCursor(); s = cm.getLine c.line
if /^ *$/.test s[...c.ch]
cm.execCommand 'indentMore'
else
emit 'Autocomplete', line: s, pos: c.ch, token: id
return
downOrXline: ->
l = cm.getCursor().line
if l != cm.lineCount() - 1 || /^\s*$/.test cm.getLine l then cm.execCommand 'goLineDown'
else cm.execCommand 'goDocEnd'; cm.execCommand 'newlineAndIndent'; xline = l + 1
return
###
F6 = -> opts.openInExternalEditor cm.getValue(), cm.getCursor().line, (err, text) ->
if err then $.alert '' + err, 'Error' else c = cm.getCursor().line; cm.setValue text; cm.setCursor c
Expand Down
4 changes: 1 addition & 3 deletions client/keymap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ bqbqc = ((s) -> join s.split('\n').map (l) ->
""" + [0...26].map((i) -> "\n#{chr i + ord ''} _#{chr i + ord 'a'}").join '' # underscored alphabet: Ⓐ _a ...

createCommand = (xx) -> CodeMirror.commands[xx] ?= (cm) -> (if (h = cm.dyalogCommands) && h[xx] then h[xx]()); return
createCommand 'CBP'
createCommand 'MA'

['CBP', 'MA', 'tabOrAutocomplete', 'downOrXline'].forEach createCommand
'''
[ 0 1 2 3 4 5 6 7 8 9 A B C D E F]
[00] QT ER TB BT EP UC DC RC LC US DS RS LS UL DL RL
Expand Down

0 comments on commit aa54f22

Please sign in to comment.