Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes for ace integration #148

Merged
merged 2 commits into from

2 participants

Matt Gruskin Wout Mertens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2012
  1. Matt Gruskin
Commits on Nov 23, 2012
  1. Matt Gruskin
This page is out of date. Refresh to see the latest.
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.3.3
(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.3.3
(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;
Something went wrong with that request. Please try again.