Skip to content

A dictation after "(", a quote, "@" or "#" is pasted with a stray leading space #333

Open

Description

@Pulkit7070

Summary

InsertionSeparator.withLeadingSeparator adds a space before the transcript whenever the character before the caret is not whitespace. That is right after a word or a sentence end. It is wrong after an opening bracket or quote, or after a prefix the user just typed for the dictated word, where no space belongs:

Typed before the caret Dictated Pasted result
Call me ( "maybe tomorrow" Call me ( Maybe tomorrow.
She said " / She said “ … She said " Maybe tomorrow.
ping @ a name ping @ Maybe…
post in # a channel post in # Maybe…
a [ … a [ Maybe…
price: $ an amount price: $ Maybe…
~/ a path ~/ Maybe…

The Mac paste path (KeyInjector) and the iOS keyboard (KeyboardModel+Phase.swift) both use this function, so both platforms are affected.

Code:

guard let priorText, let last = priorText.last, !last.isWhitespace else { return text }

Related but different: #206 (#206) and #208 (#208) were about the same-window fallback adding a space when the caret had moved. This report is about the separator rule itself, when the text before the caret is known.

Repro

On main (6739585), add to Tests/BlurtEngineTests/ and run DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test --filter SeparatorOpeners:

import Testing
@testable import BlurtEngine

@Suite("SeparatorOpeners")
struct SeparatorOpenersTests {
  @Test(arguments: ["Call me (", "She said \"", "She said “", "ping @", "post in #", "a ["])
  func noSpaceAfterAnOpener(prior: String) {
    #expect(InsertionSeparator.withLeadingSeparator("Maybe tomorrow.", after: prior) == "Maybe tomorrow.")
  }
}

Expected

No separator after an opening bracket, an opening quote, or @/#: Call me (Maybe tomorrow.

Actual

Every case gets a leading space:

prior=[Call me (]  pasted=[Call me ( Maybe tomorrow.]
prior=[She said "] pasted=[She said " Maybe tomorrow.]
prior=[ping @]     pasted=[ping @ Maybe tomorrow.]
prior=[post in #]  pasted=[post in # Maybe tomorrow.]

Suggested fix

Skip the separator when the last character of the prior text is an opener:

guard let priorText, let last = priorText.last, !last.isWhitespace,
  !"([{\"“‘'@#$/".contains(last) else { return text }

Treat a straight " or ' as an opener only when the character before it is whitespace or the start of the text, so a closing quote still gets its space. With the simple version above, the existing InsertionSeparator and KeyInjector suites still pass. Which prefixes count ($, /, -) is a judgment call for the maintainers. Brackets, opening quotes, @ and # are the clear cases.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions