Created
November 8, 2011 20:02
-
-
Save ericallam/1348983 to your computer and use it in GitHub Desktop.
Set certain regions of an Ace editor to readOnly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@tripflex Hey , In this e.preventDefault will not throw error?