From: Aleksander Ɓukasz Date: Wed, 19 Jun 2013 07:34:41 +0000 (+0200) Subject: Preventing browser from removing node when last character gets deleted via backspace X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/c1710d2ef0a9d01b495a16f290959e4f21f10911?hp=540ab2ebda6121a52a15f82e531ef8ba558024b1 Preventing browser from removing node when last character gets deleted via backspace --- diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index bb8ad4a..4e61b88 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -51,6 +51,15 @@ return function(sandbox) { e.preventDefault(); view.insertNewNode(null, null); } + if(e.which === 8) { + var anchor = window.getSelection().anchorNode; + var len = anchor.length; + console.log(len); + if(len === 1) { + e.preventDefault(); + $(anchor).parent().text(''); + } + } }); this.node.onShow = function() {