From e699073d457c54b7a61629a57102230787df4a26 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 29 Mar 2016 11:54:55 +0200 Subject: [PATCH] attempt to preserve the magic line plugin while someone else is typing --- www/_socket/main.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/www/_socket/main.js b/www/_socket/main.js index 5e504bb47..1dc106ed4 100644 --- a/www/_socket/main.js +++ b/www/_socket/main.js @@ -84,12 +84,31 @@ define([ var diffOptions = { preDiffApply: function (info) { - /* TODO DiffDOM will filter out magicline plugin elements + /* DiffDOM will filter out magicline plugin elements in practice this will make it impossible to use it - while someone else is typing, which could be annoying + while someone else is typing, which could be annoying. we should check when such an element is going to be removed, and prevent that from happening. */ + if (info.node && info.node.tagName === 'SPAN' && + info.node.contentEditable === "true") { + // it seems to be a magicline plugin element... + if (info.diff.action === 'removeElement') { + // and you're about to remove it... + // this probably isn't what you want + + /* + I have never seen this in the console, but the + magic line is still getting removed on remote + edits. This suggests that it's getting removed + by something other than diffDom. + */ + console.log("preventing removal of the magic line!"); + + // return true to prevent diff application + return true; + } + } // no use trying to recover the cursor if it doesn't exist if (!cursor.exists()) { return; }