Nekochu commited on
Commit
87e03d2
·
verified ·
1 Parent(s): d36cf5b

Scrolling: wheel fallback, answer scroll area, jump to answer

Browse files
Files changed (2) hide show
  1. main.js +13 -0
  2. style.css +1 -1
main.js CHANGED
@@ -68,8 +68,21 @@ function linkify(node, text) {
68
  }
69
  function showAnswer(text, short) {
70
  ui.answer.hidden = false; ui.short.textContent = short || ''; linkify(ui.report, text.trim());
 
71
  }
72
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  // ---------------------------------------------------------------- tools (run in this page: tools.js)
74
  async function callTool(name, args, signal) {
75
  setSignal(signal);
 
68
  }
69
  function showAnswer(text, short) {
70
  ui.answer.hidden = false; ui.short.textContent = short || ''; linkify(ui.report, text.trim());
71
+ ui.answer.scrollIntoView({ block: 'start' }); // land on the start of the answer
72
  }
73
 
74
+ // Belt and braces for iframes that swallow wheel scrolling (seen in the Space's embedded view): if a wheel turn did not move anything,
75
+ // scroll the page ourselves. An inner scroller (a step's output) that did take the wheel is left alone.
76
+ addEventListener('wheel', (e) => {
77
+ if (e.ctrlKey || e.defaultPrevented) return;
78
+ const page = document.body, inner = e.target.closest?.('pre, .think, #report'), b0 = page.scrollTop, i0 = inner ? inner.scrollTop : 0;
79
+ requestAnimationFrame(() => requestAnimationFrame(() => {
80
+ if (page.scrollTop !== b0 || (inner && inner.scrollTop !== i0)) return;
81
+ const dy = e.deltaMode === 1 ? e.deltaY * 40 : e.deltaMode === 2 ? e.deltaY * page.clientHeight : e.deltaY, max = page.scrollHeight - page.clientHeight;
82
+ if ((dy > 0 && b0 < max) || (dy < 0 && b0 > 0)) page.scrollTop = b0 + dy;
83
+ }));
84
+ }, { passive: true });
85
+
86
  // ---------------------------------------------------------------- tools (run in this page: tools.js)
87
  async function callTool(name, args, signal) {
88
  setSignal(signal);
style.css CHANGED
@@ -35,7 +35,7 @@ button:disabled { opacity: .55; cursor: default; }
35
  #answer h2 { margin: 4px 0; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
36
  #short { margin: 4px 0 8px; font-size: 20px; font-weight: 600; }
37
  #short:empty { display: none; }
38
- #report { white-space: pre-wrap; overflow-wrap: anywhere; }
39
 
40
  #trail { display: grid; gap: 6px; }
41
  .step { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 13.5px; }
 
35
  #answer h2 { margin: 4px 0; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
36
  #short { margin: 4px 0 8px; font-size: 20px; font-weight: 600; }
37
  #short:empty { display: none; }
38
+ #report { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 70vh; overflow-y: auto; } /* the answer scrolls by itself too */
39
 
40
  #trail { display: grid; gap: 6px; }
41
  .step { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 13.5px; }