Changeset f8e8f9e in Klonkt


Ignore:
Timestamp:
06/19/2026 12:09:06 PM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
2d596cf
Parents:
cbfbf88
Message:

fix(editor): more robust anti-jump on formatting (Chrome)

keepScroll now captures ALL scrollable ancestors of the editor (editor,
frame, #pcms-main, …) as well as the page, and restores sync + over 2
extra frames — Chrome sometimes scrolls the caret into view one frame
later. Replaces the window+editor-only restore that failed to catch the
jump on Chrome.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/pages/post-edit.ejs

    rcbfbf88 rf8e8f9e  
    10761076  // Houd de scrollpositie vast rond een edit-commando. execCommand/insert scrollt
    10771077  // standaard de caret in beeld → het beeld "verspringt" bij het aanklikken van een
    1078   // opmaakknop. Door de positie te bewaren en terug te zetten (sync + na 1 frame)
    1079   // blijft het beeld staan; de gebruiker scrollt zelf.
     1078  // opmaakknop. We leggen ALLE scrollbare voorouders (editor, frame, #pcms-main, …)
     1079  // + de pagina vast en zetten ze terug — sync én over een paar frames, want Chrome
     1080  // scrollt soms pas een frame later. De gebruiker scrollt zo zelf.
     1081  function scrollableAncestors(el) {
     1082    const list = [];
     1083    let node = el;
     1084    while (node && node !== document.body && node !== document.documentElement) {
     1085      const oy = getComputedStyle(node).overflowY;
     1086      if (oy === 'auto' || oy === 'scroll' || oy === 'overlay') list.push(node);
     1087      node = node.parentElement;
     1088    }
     1089    return list;
     1090  }
    10801091  function keepScroll(fn) {
    1081     const x = window.scrollX, y = window.scrollY, es = editor.scrollTop;
     1092    const wx = window.scrollX, wy = window.scrollY;
     1093    const anc = scrollableAncestors(editor).map(function (n) { return [n, n.scrollTop, n.scrollLeft]; });
     1094    const restore = function () {
     1095      window.scrollTo(wx, wy);
     1096      anc.forEach(function (e) { e[0].scrollTop = e[1]; e[0].scrollLeft = e[2]; });
     1097    };
    10821098    fn();
    1083     window.scrollTo(x, y); editor.scrollTop = es;
    1084     requestAnimationFrame(function () { window.scrollTo(x, y); editor.scrollTop = es; });
     1099    restore();
     1100    requestAnimationFrame(restore);
     1101    requestAnimationFrame(function () { requestAnimationFrame(restore); });
    10851102  }
    10861103  function execCmd(cmd, arg) {
Note: See TracChangeset for help on using the changeset viewer.