Changeset a7e8e19 in Klonkt for src/views/pages/post-edit.ejs


Ignore:
Timestamp:
06/19/2026 10:34:24 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
16ce669
Parents:
f83ccf3
Message:

fix(editor): mobile — formatting buttons no longer steal focus (toggle + no jump)

Toolbar buttons called editor.focus() on click after the tap had already
moved focus/selection out of the contenteditable field → bold/italic
could not be toggled off and the page jumped to the caret. Now
mousedown-preventDefault on the toolbar (focus stays in the editor) +
editor.focus({preventScroll:true}) + touch-action:manipulation for snappy
taps.

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

File:
1 edited

Legend:

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

    rf83ccf3 ra7e8e19  
    393393  width: 32px; height: 32px;
    394394  padding: 0;
     395  touch-action: manipulation; /* snappy taps op mobiel, geen dubbeltik-zoom */
     396  -webkit-user-select: none; user-select: none;
    395397  background: transparent;
    396398  border: 1px solid transparent;
     
    10371039  // ── Toolbar wiring
    10381040  function execCmd(cmd, arg) {
    1039     editor.focus();
     1041    editor.focus({ preventScroll: true });
    10401042    document.execCommand(cmd, false, arg);
    10411043    updateToolbarState();
     
    10551057    sel.removeAllRanges();
    10561058    sel.addRange(range);
    1057     editor.focus();
     1059    editor.focus({ preventScroll: true });
    10581060  }
    10591061  function linkPrompt() {
     
    10771079  // pak de wrapper uit; anders pas blockquote toe.
    10781080  function toggleBlockquote() {
    1079     editor.focus();
     1081    editor.focus({ preventScroll: true });
    10801082    const bq = blockquoteAncestor();
    10811083    if (bq) {
     
    11071109
    11081110  if (toolbar) {
     1111    // CRUCIAAL (mobiel + desktop): voorkom dat een toolbar-knop de focus/selectie
     1112    // uit het editor-veld steelt. Zonder dit raakt de selectie kwijt bij het tikken
     1113    // → execCommand werkt op een lege selectie (vet kan niet meer UIT) én de browser
     1114    // scrollt de caret opnieuw in beeld (de "sprong naar beneden"). preventDefault op
     1115    // mousedown houdt de focus in de editor; de click blijft gewoon vuren.
     1116    toolbar.addEventListener('mousedown', (e) => {
     1117      if (e.target.closest('button')) e.preventDefault();
     1118    });
    11091119    toolbar.addEventListener('click', (e) => {
    11101120      const btn = e.target.closest('button[data-cmd]');
     
    11661176      const j = await uploadImage(file);
    11671177      const img = '<img src="' + j.url + '" alt="">';
    1168       editor.focus();
     1178      editor.focus({ preventScroll: true });
    11691179      document.execCommand('insertHTML', false, img);
    11701180      contentStatus.textContent = 'Ingevoegd ✓';
     
    12041214  // ── Insert chip helpers (track / playlist)
    12051215  function insertChip(kind, value) {
    1206     editor.focus();
     1216    editor.focus({ preventScroll: true });
    12071217    const chip = makeChip(kind, value);
    12081218    // Insert at caret using the Selection API (execCommand insertNode)
Note: See TracChangeset for help on using the changeset viewer.