Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #148 from obijywk/ace

Fixes for ace integration
  • Loading branch information...
commit 9477f6ddd9c2df82f65afe1aaf5a36b9cf54aae8 2 parents 7d9faa9 + a9f513b
Wout Mertens wmertens authored
9 src/client/ace.coffee
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,13 +107,13 @@ 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
@@ -120,6 +121,8 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents) ->
check()
doc.detach_ace = ->
+ doc.removeListener 'insert', insertListener
+ doc.removeListener 'delete', deleteListener
doc.removeListener 'remoteop', docListener
editorDoc.removeListener 'change', editorListener
delete doc.detach_ace
14 webclient/ace.js
View
@@ -1,8 +1,10 @@
// Generated by CoffeeScript 1.4.0
(function() {
- var Range, applyToShareJS;
+ var Range, applyToShareJS, requireImpl;
- Range = require("ace/range").Range;
+ requireImpl = ace.require != null ? ace.require : require;
+
+ Range = requireImpl("ace/range").Range;
applyToShareJS = function(editorDoc, delta, doc) {
var getStartOffsetPosition, pos, text;
@@ -38,7 +40,7 @@
};
window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
- var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
+ var check, deleteListener, doc, docListener, editorDoc, editorListener, insertListener, offsetToPos, suppress;
if (!this.provides['text']) {
throw new Error('Only text documents can be attached to ace');
}
@@ -95,13 +97,13 @@
column: offset
};
};
- doc.on('insert', function(pos, text) {
+ doc.on('insert', insertListener = function(pos, text) {
suppress = true;
editorDoc.insert(offsetToPos(pos), text);
suppress = false;
return check();
});
- doc.on('delete', function(pos, text) {
+ doc.on('delete', deleteListener = function(pos, text) {
var range;
suppress = true;
range = Range.fromPoints(offsetToPos(pos), offsetToPos(pos + text.length));
@@ -110,6 +112,8 @@
return check();
});
doc.detach_ace = function() {
+ doc.removeListener('insert', insertListener);
+ doc.removeListener('delete', deleteListener);
doc.removeListener('remoteop', docListener);
editorDoc.removeListener('change', editorListener);
return delete doc.detach_ace;
14 webclient/share-ace.js
View
@@ -1,8 +1,10 @@
// Generated by CoffeeScript 1.4.0
(function() {
- var Range, applyToShareJS;
+ var Range, applyToShareJS, requireImpl;
- Range = require("ace/range").Range;
+ requireImpl = ace.require != null ? ace.require : require;
+
+ Range = requireImpl("ace/range").Range;
applyToShareJS = function(editorDoc, delta, doc) {
var getStartOffsetPosition, pos, text;
@@ -38,7 +40,7 @@
};
window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
- var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
+ var check, deleteListener, doc, docListener, editorDoc, editorListener, insertListener, offsetToPos, suppress;
if (!this.provides['text']) {
throw new Error('Only text documents can be attached to ace');
}
@@ -95,13 +97,13 @@
column: offset
};
};
- doc.on('insert', function(pos, text) {
+ doc.on('insert', insertListener = function(pos, text) {
suppress = true;
editorDoc.insert(offsetToPos(pos), text);
suppress = false;
return check();
});
- doc.on('delete', function(pos, text) {
+ doc.on('delete', deleteListener = function(pos, text) {
var range;
suppress = true;
range = Range.fromPoints(offsetToPos(pos), offsetToPos(pos + text.length));
@@ -110,6 +112,8 @@
return check();
});
doc.detach_ace = function() {
+ doc.removeListener('insert', insertListener);
+ doc.removeListener('delete', deleteListener);
doc.removeListener('remoteop', docListener);
editorDoc.removeListener('change', editorListener);
return delete doc.detach_ace;
Please sign in to comment.
Something went wrong with that request. Please try again.