Permalink
Browse files

Merge pull request #148 from obijywk/ace

Fixes for ace integration
  • Loading branch information...
2 parents 7d9faa9 + a9f513b commit 9477f6ddd9c2df82f65afe1aaf5a36b9cf54aae8 @wmertens wmertens committed Jan 18, 2013
Showing with 24 additions and 13 deletions.
  1. +6 −3 src/client/ace.coffee
  2. +9 −5 webclient/ace.js
  3. +9 −5 webclient/share-ace.js
View
@@ -1,6 +1,7 @@
# This is some utility code to connect an ace editor to a sharejs document.
-Range = require("ace/range").Range
+requireImpl = if ace.require? then ace.require else require
+Range = requireImpl("ace/range").Range
# Convert an ace delta into an op understood by share.js
applyToShareJS = (editorDoc, delta, doc) ->
@@ -106,20 +107,22 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents) ->
row:row, column:offset
- doc.on 'insert', (pos, text) ->
+ doc.on 'insert', insertListener = (pos, text) ->
suppress = true
editorDoc.insert offsetToPos(pos), text
suppress = false
check()
- doc.on 'delete', (pos, text) ->
+ doc.on 'delete', deleteListener = (pos, text) ->
suppress = true
range = Range.fromPoints offsetToPos(pos), offsetToPos(pos + text.length)
editorDoc.remove range
suppress = false
check()
doc.detach_ace = ->
+ doc.removeListener 'insert', insertListener
+ doc.removeListener 'delete', deleteListener
doc.removeListener 'remoteop', docListener
editorDoc.removeListener 'change', editorListener
delete doc.detach_ace
View
Oops, something went wrong.
View
Oops, something went wrong.

0 comments on commit 9477f6d

Please sign in to comment.