Teleprompter text starts at the top of the floating window instead of vertically centered (word-tracking mode)

未关闭 适合新手
#92 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
swift
领域
desktop

调研方向

从 MarqueeTextView.swift 开始,检查 SpeechScrollView 的 isListening 变更处理程序和现有的 geo.size.height 处理程序。比较它们在初始状态下的行为,然后在 Floating Window + Word Tracking 和 Silence-Paused 模式中验证:开始识别时第一行仍保持垂直居中,同时不改变 Classic 模式的行为。

由索引模型根据 Issue 内容生成。

描述

Version: 1.6.5 (reproduced on master, commit 1b2f26d)
Mode: Floating Window + Word Tracking

Summary

When the teleprompter opens, the first line is supposed to sit roughly halfway down the window, leaving blank space above it that fills in as the text scrolls up. In Word Tracking mode this doesn't happen — the first line is pinned to the very top of the window, partly clipped by the fade at the top inner edge, and it never moves down.

The offset is computed correctly when the view appears, then gets overwritten ~400ms later when speech recognition starts.

Steps to reproduce
  1. Settings → Overlay Mode → Floating Window (leave "Follow cursor when undocked" off)
  2. Settings → Listening Mode → Word Tracking
  3. Start the teleprompter
Expected

First line of text roughly vertically centered, with blank space above it.

Actual

First line sits flush at the top of the window and stays there.

Mode dependency

This only reproduces in Word Tracking (and should apply to Silence-Paused for the same reason). In Classic mode it does not occur.

The difference is isEffectivelyListening (NotchOverlayController.swift):

case .wordTracking, .silencePaused:
    return speechRecognizer.isListening   // starts false, flips true when recognition starts
case .classic:
    return !isPaused                      // already true on first render, never changes

In Classic the value never changes, so the onChange handler below never fires. In Word Tracking it flips false → true shortly after the window opens, and that's what triggers the bug.

Root cause

MarqueeTextView.swift, SpeechScrollView:

  • .onAppear (line 172) correctly sets the initial offset: scrollOffset = containerHeight * 0.5 - lineHeight * 0.5
  • .onChange(of: isListening) (line 159) then calls recalcCenter(containerHeight:) when recognition starts
  • recalcCenter (line 249) computes target = center - wordY — the formula for keeping the active word centered mid-scroll. In the initial state, with highlightedCharCount == 0, this produces a value that collapses the offset to ~0.

Note that .onChange(of: geo.size.height) (line 137) already guards this exact situation:

if highlightedCharCount == 0 && smoothWordProgress == 0 {
    // Initial state: center first line on screen
    let lineHeight = font.pointSize * 1.4
    scrollOffset = newHeight * 0.5 - lineHeight * 0.5
} else if isListening {
    recalcCenter(containerHeight: newHeight)
}

The isListening handler has no equivalent guard, so it calls recalcCenter unconditionally.

Trace

Instrumented run, 480×360 floating window, XL font, Word Tracking:

prefChange  wasEmpty=true  count=113  h=0.0    offset=0.0
recalcCenter h=0.0  smooth=false idx=0 yPos=113 offset=0.0
onAppear    h=312.0  words=113
prefChange  wasEmpty=false count=98   h=312.0  offset=139.2   <- correct
onChange(isListening)=true            h=312.0  offset=139.2
recalcCenter h=312.0 smooth=false idx=0 yPos=98 offset=139.2
prefChange  wasEmpty=false count=113  h=312.0  offset=2.8     <- collapsed to top

onAppear sets 139.2 (correct: 312/2 - 33.6/2). Roughly 390ms later isListening flips true, recalcCenter runs, and the offset drops to 2.8 — the text jumps to the top and stays there.

Note

Resizing the window afterwards fixes it, because that fires .onChange(of: geo.size.height), which does have the initial-state guard and restores the correct offset. That's a useful confirmation of the diagnosis, and also why the bug can look intermittent.

Suggested direction

Apply the same initial-state guard already used in the geo.size.height handler, so recalcCenter isn't called before any text has been spoken. Happy to open a PR if that approach sounds right.

主要语言
Swift
星标
4.2k
派生
296
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

f/textream 的其他 Issue

查看 f/textream 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。