From: Radek Czajka Date: Tue, 27 Jun 2023 10:18:22 +0000 (+0200) Subject: Fix caret positioning outside editable. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/732fe46593ff27a62c6f64f3d495c3d5619ece1c?hp=4cab8b0725fd5a88f5a508e584b4acd346a824fc Fix caret positioning outside editable. --- diff --git a/src/redakcja/static/js/wiki/caret.js b/src/redakcja/static/js/wiki/caret.js index 8b3cbd84..7026e2f5 100644 --- a/src/redakcja/static/js/wiki/caret.js +++ b/src/redakcja/static/js/wiki/caret.js @@ -28,12 +28,15 @@ class Caret { var selection = window.getSelection(); if (!selection.isCollapsed) return; + var anchorNode = selection.anchorNode; + // Is selection still inside a node? + if (!$(anchorNode).closest('[x-node]')) return; self.singleClick = true; setTimeout(function() { if (self.singleClick) { self.element.insertBefore( - selection.anchorNode.splitText( + anchorNode.splitText( selection.anchorOffset ) )