From 6ec7c40f8eeaaa761e0059e562fea07668317f74 Mon Sep 17 00:00:00 2001 From: lqdev Date: Sun, 18 Feb 2024 12:36:53 +0100 Subject: [PATCH] make the editor a bit more usable --- static/js/vendor/codejar.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/static/js/vendor/codejar.js b/static/js/vendor/codejar.js index 4942b89..95f0ad0 100644 --- a/static/js/vendor/codejar.js +++ b/static/js/vendor/codejar.js @@ -58,6 +58,30 @@ export function CodeJar(editor, highlight, opt = {}) { listeners.push([type, fn]); editor.addEventListener(type, fn); }; + + // PATCH(liquidex): Prevent cursor jank in Firefox. + on('beforeinput', event => { + if (isLegacy) { + if (event.inputType == "deleteContentBackward") { + event.preventDefault(); + + let position = save(); + document.execCommand("delete"); + if (position.end != position.start) { + if (position.dir == "->") { + position.end = position.start; + } else { + position.start = position.end; + } + } else { + position.start -= 1; + position.end = position.start; + } + restore(position); + } + } + }); + on('keydown', event => { if (event.defaultPrevented) return;