Skip to content

Instantly share code, notes, and snippets.

@BinaryMuse
Forked from ericallam/app.coffee
Created May 24, 2013 07:03
Show Gist options
  • Save BinaryMuse/5641768 to your computer and use it in GitHub Desktop.
Save BinaryMuse/5641768 to your computer and use it in GitHub Desktop.
event = require('pilot/event')
Anchor = require('ace/anchor').Anchor
doc = ace_editor.session.getDocument()
editablePositions = [[1, 0, 2, 0]] # allow editong only the second row
jQuery.each editable, (index, row) ->
editablePositions.push [new Anchor(doc, row[0], row[1]), new Anchor(doc, row[2], row[3])]
Range = require('ace/range').Range
event.addListener(jQuery('#ace textarea')[0], 'keydown', (e) ->
# console.log e.type, e.charCode, e.keyCode, e
position = ace_editor.getCursorPosition()
setReadOnly = false
jQuery.each editablePositions, (index, editableAnchors) ->
editableRange = Range.fromPoints editableAnchors[0].getPosition(), editableAnchors[1].getPosition()
setReadOnly = !editableRange.contains(position.row, position.column)
ace_editor.setReadOnly setReadOnly
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment