Replaces compareDeltaObjects with editor.curOp
This commit is contained in:

committed by
Sebastian Serth

parent
735a74901f
commit
6e0dc9d7bc
@ -29,7 +29,6 @@ var CodeOceanEditor = {
|
|||||||
running: false,
|
running: false,
|
||||||
|
|
||||||
lastCopyText: null,
|
lastCopyText: null,
|
||||||
lastDeltaObject_for_file: new Map(),
|
|
||||||
|
|
||||||
<% self.class.include Rails.application.routes.url_helpers %>
|
<% self.class.include Rails.application.routes.url_helpers %>
|
||||||
<% @config ||= CodeOcean::Config.new(:code_ocean).read(erb: false) %>
|
<% @config ||= CodeOcean::Config.new(:code_ocean).read(erb: false) %>
|
||||||
@ -313,7 +312,6 @@ var CodeOceanEditor = {
|
|||||||
editor.commands.bindKey("ctrl+alt+0", null);
|
editor.commands.bindKey("ctrl+alt+0", null);
|
||||||
this.editors.push(editor);
|
this.editors.push(editor);
|
||||||
this.editor_for_file.set($(element).parent().data('filename'), editor);
|
this.editor_for_file.set($(element).parent().data('filename'), editor);
|
||||||
this.lastDeltaObject_for_file.set($(element).parent().data('filename'), null);
|
|
||||||
var session = editor.getSession();
|
var session = editor.getSession();
|
||||||
var mode = $(element).data('mode')
|
var mode = $(element).data('mode')
|
||||||
session.setMode(mode);
|
session.setMode(mode);
|
||||||
@ -335,9 +333,11 @@ var CodeOceanEditor = {
|
|||||||
editor.on("copy", this.handleCopyEvent.bind(element));
|
editor.on("copy", this.handleCopyEvent.bind(element));
|
||||||
|
|
||||||
// listener for autosave
|
// listener for autosave
|
||||||
session.on("change", function (deltaObject, session) {
|
session.on("change", function (editor, deltaObject, session) {
|
||||||
if (this.compareDeltaObjects(deltaObject, this.lastDeltaObject_for_file.get(this.active_file.filename))) {
|
// editor.curOp.command is empty for changes that are not caused by user input.
|
||||||
this.lastDeltaObject_for_file.set(this.active_file.filename, null);
|
// With that we can differentiate between changes caused by user input and
|
||||||
|
// changes caused by changed text because of WebSocket notifications from a pair programming partner.
|
||||||
|
if(_.isEmpty(editor.curOp.command)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
App.synchronized_editor?.editor_change(deltaObject, this.active_file);
|
App.synchronized_editor?.editor_change(deltaObject, this.active_file);
|
||||||
@ -345,7 +345,7 @@ var CodeOceanEditor = {
|
|||||||
// TODO: This is a workaround for a bug in Ace. Remove when upgrading Ace.
|
// TODO: This is a workaround for a bug in Ace. Remove when upgrading Ace.
|
||||||
this.handleUTF16Surrogates(deltaObject, session);
|
this.handleUTF16Surrogates(deltaObject, session);
|
||||||
this.resetSaveTimer();
|
this.resetSaveTimer();
|
||||||
}.bind(this));
|
}.bind(this, editor));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1061,20 +1061,10 @@ var CodeOceanEditor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
applyChanges: function (delta, active_file) {
|
applyChanges: function (delta, active_file) {
|
||||||
this.lastDeltaObject_for_file.set(active_file.filename, delta);
|
|
||||||
const editor = this.editor_for_file.get(active_file.filename)
|
const editor = this.editor_for_file.get(active_file.filename)
|
||||||
editor.session.doc.applyDeltas([delta]);
|
editor.session.doc.applyDeltas([delta]);
|
||||||
},
|
},
|
||||||
|
|
||||||
compareDeltaObjects: function (delta, last_delta) {
|
|
||||||
if (delta === null || last_delta === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const delta_data = delta.data
|
|
||||||
return !_.isEqual(delta_data, last_delta);
|
|
||||||
},
|
|
||||||
|
|
||||||
showPartnersConnectionStatus: function (status, username) {
|
showPartnersConnectionStatus: function (status, username) {
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case 'connected':
|
case 'connected':
|
||||||
|
Reference in New Issue
Block a user