Compare commits

...
2 Commits
Author SHA1 Message Date
ays953 251a16fa08 Release v0.7.0 2026-11-11 16:29:06 +08:00
ays953andClaude Opus 5.5 7cb1f62dfa Backtick + punctuation key forces a full-width symbol
` then , . / ; : ' [ ] ( ) ! ~ - = and their shifted keys always give the
full-width symbol (,。?;:、「」()!~——=), whatever the context. Backtick
followed by any other key is a plain backtick, so ``` still works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:28:54 +08:00
8 changed files with 133 additions and 8 deletions
+3 -2
View File
@@ -16,7 +16,7 @@
- **注音順序打錯也能修正**:`ㄧㄒㄠˇ`、`ㄒㄠㄧˇ` 都會變成 `ㄒㄧㄠˇ`(小)
- **可省略聲調**:`jiap7`(ㄨㄛ ㄇㄣ˙)一樣能打出「我們」
- **候選字**:用 ← → 把游標移到要改的字後面,按 ↓ 選字;選過的會固定下來
- **全形標點**:中文語境下 `?` `!` `<` 自動變成 `?` `!` `,`
- **全形標點**:中文語境下 `?` `!` `<` 自動變成 `?` `!` `,`;任何時候按 `` ` `` 再按標點鍵,一定得到全形標點(例如 `` `< `` = `,`)
- **完整詞庫**:約 17 萬筆,來自小麥注音 McBopomofo(MIT 授權)
## 下載與安裝
@@ -58,6 +58,7 @@ SmartScreen 出現警告時,按「其他資訊 → 仍要執行」。解除安
| Shift + 字母 | 打大寫字母(也會強制英文) |
| `< > ? ! : ( ) [ ]` | 中文語境下自動轉成全形 `,。?!:()「」` |
| `, . / ; -` | 英文單字後是標點;在注音中是 ㄝ ㄡ ㄥ ㄤ ㄦ(例如 `2;3` = 檔) |
| `` ` `` + 標點鍵 | **強制全形標點**,不管前後是中文還是英文:`` `, `` `` `< `` = `,`、`` `. `` `` `> `` = `。`、`` `/ `` = `?`、`` `; `` = `;`、`` `: `` = `:`、`` `' `` `` `\ `` = `、`、`` `[ `` `` `] `` = `「」`、`` `{ `` `` `} `` = `『』`、`` `( `` `` `) `` = `()`、`` `! `` = `!`、`` `~ `` = `~`、`` `- `` = `——`、`` `= `` = `=`。`` ` `` 後面接其他鍵就是普通的反引號(` ``` ` 照常可用) |
## 運作方式
@@ -217,7 +218,7 @@ training/ 合成資料、訓練權重、Swift/Python 一致
- Windows 版還沒在實機上測試過。
- 聲調鍵打在注音符號中間(例如 `uv3l`)無法自動修正。
- 很短的字串(如 `up` 是英文還是 ㄧㄣ)本質上就有歧義,可能需要按 Tab 修正;修正後會記住。
- 很短的字串本質上就有歧義。像 `up`(也是 ㄧㄣ 因)這種常用的,按空白後會先保留,看下一個詞再決定(`up jo4` = 因為、`up the` = up the);其他判斷錯的可以按 Tab 修正,修正後會記住。
- 安裝檔沒有簽章(macOS 沒有 Developer ID,Windows 沒有程式碼簽章憑證)。
## 下一步(Roadmap)
+2 -2
View File
@@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.6.3</string>
<string>0.7.0</string>
<key>CFBundleVersion</key>
<string>11</string>
<string>12</string>
<key>InputMethodConnectionName</key>
<string>com.autozhuyin.inputmethod.AutoZhuyin_Connection</string>
<key>InputMethodServerControllerClass</key>
+32 -1
View File
@@ -55,6 +55,9 @@ public final class CompositionEngine {
/// reading ("up " = ㄧㄣ 因) is not committed on space; the next word decides
/// ("up jo4" = 因為, "up the" = up the).
private var held: Int?
/// "`" was typed: if the next key is in `symbols` it gives that full-width symbol
/// whatever the context; anything else makes it a plain backtick (so ``` still works).
public private(set) var pendingBacktick = false
static let holdMinScore = -3.5
private var previousMode: InputMode?
@@ -115,9 +118,11 @@ public final class CompositionEngine {
public var markedPieces: [MarkedPiece] {
let segs = segments
return segs.enumerated().map { i, seg in
var pieces = segs.enumerated().map { i, seg in
MarkedPiece(text: render(seg, final: i < segs.count - 1), mode: seg.mode)
}
if pendingBacktick { pieces.append(MarkedPiece(text: "`", mode: .literal)) }
return pieces
}
/// Text for one segment. A non-final Zhuyin segment shows its unfinished syllable as Bopomofo.
@@ -186,6 +191,7 @@ public final class CompositionEngine {
public func handle(_ key: KeyInput) -> KeyResult {
if isShowingCandidates { return handleCandidateKey(key) }
if pendingBacktick { return afterBacktick(key) }
switch key {
case .character(let c):
@@ -245,6 +251,10 @@ public final class CompositionEngine {
cursor = nil // typing always continues at the end
// English mode: every key goes to the app as typed.
if isEnglishMode && keys.isEmpty { return .passThrough }
if c == "`" {
pendingBacktick = true
return .consumed
}
if c == " " {
guard !keys.isEmpty else { return .passThrough }
let segs = segments(of: keys, finishing: true)
@@ -290,6 +300,26 @@ public final class CompositionEngine {
return ZhuyinParser.parse(Array(keys[last.range]))
}
private func afterBacktick(_ key: KeyInput) -> KeyResult {
pendingBacktick = false
if key == .escape || key == .backspace { return .consumed }
let committed = keys.isEmpty ? "" : commitCurrent()
if case .character(let c) = key, let symbol = CompositionEngine.symbols[c] {
return KeyResult(handled: true, commit: committed + symbol)
}
// Not a symbol: the backtick was meant literally; then handle the key as usual.
var r = handle(key)
if !r.handled, case .character(let c) = key { r = KeyResult(handled: true, commit: String(c)) }
return KeyResult(handled: r.handled, commit: committed + "`" + (r.commit ?? ""))
}
/// "`" + key → full-width symbol.
static let symbols: [Character: String] = [
",": ",", "<": ",", ".": "。", ">": "。", "/": "?", "?": "?", ";": ";", ":": ":",
"'": "、", "\\": "、", "\"": "「", "[": "「", "]": "」", "{": "『", "}": "』",
"(": "(", ")": ")", "!": "!", "~": "~", "-": "——", "_": "——", "=": "=",
]
static let fullwidth: [Character: String] = [
"<": ",", ">": "。", "?": "?", "!": "!", ":": ":", "\"": "「", "(": "(", ")": ")",
"{": "『", "}": "』", "[": "「", "]": "」", "~": "~", "_": "——",
@@ -363,6 +393,7 @@ public final class CompositionEngine {
public func reset() {
keys = []
held = nil
pendingBacktick = false
cursor = nil
forcedMode = nil
fixed = [:]
@@ -462,6 +462,44 @@ final class HeldWordTests: XCTestCase {
}
}
final class BacktickSymbolTests: XCTestCase {
func makeEngine() -> CompositionEngine {
CompositionEngine(classifier: Classifier(lexicon: sharedLexicon, english: sharedEnglish, weights: sharedWeights))
}
func type(_ s: String, into e: CompositionEngine) -> String {
var out = ""
for c in s {
let key: KeyInput = c == "\n" ? .enter : .character(c)
let r = e.handle(key)
if let t = r.commit { out += t } else if !r.handled { out.append(c) }
}
return out
}
func testForcedSymbols() {
let cases = ["`<": ",", "`.": "。", "`?": "?", "`;": ";", "`[": "「",
"hello`,": "hello,", "su3cl3`.": "你好。", "```\n": "```"]
for (keys, want) in cases {
XCTAssertEqual(type(keys, into: makeEngine()), want, keys)
}
}
func testPlainBacktick() {
let e = makeEngine()
XCTAssertEqual(type("`", into: e), "")
XCTAssertEqual(e.markedText, "`")
XCTAssertEqual(type("ls` ", into: e), "`ls` ")
}
func testBackspaceCancels() {
let e = makeEngine()
_ = type("su3`", into: e)
_ = e.handle(.backspace)
XCTAssertEqual(e.markedText, "你")
}
}
final class StartupTimingTests: XCTestCase {
func testStartupTiming() throws {
var t = Date()
+34 -2
View File
@@ -24,6 +24,15 @@ FULLWIDTH = {
# is not committed on space; the next word decides ("up jo4" = 因為, "up the" = up the).
HOLD_MIN_SCORE = -3.5
# "`" then one of these keys always gives the full-width symbol, whatever the context.
# "`" followed by anything else is just a backtick (so ``` still works).
BACKTICK = "`"
SYMBOLS = {
",": ",", "<": ",", ".": "。", ">": "。", "/": "?", "?": "?", ";": ";", ":": ":",
"'": "、", "\\": "、", '"': "「", "[": "「", "]": "」", "{": "『", "}": "』",
"(": "(", ")": ")", "!": "!", "~": "~", "-": "——", "_": "——", "=": "=",
}
PASS = (False, None)
CONSUMED = (True, None)
@@ -41,6 +50,7 @@ class CompositionEngine:
# English mode, toggled by a Shift tap when nothing is being typed: keys go straight
# to the app (no composition, no underline) until Shift is tapped again.
self.english_mode = False
self.backtick = False # "`" typed; the next key may be a forced symbol
self.fixed = {} # zhuyin segment start -> {(syl_start, syl_end): text}
self.candidates = []
self.candidate_index = 0
@@ -171,7 +181,10 @@ class CompositionEngine:
@property
def marked_pieces(self):
segs = self.segments
return [(self._render(s, i < len(segs) - 1), s[2]) for i, s in enumerate(segs)]
pieces = [(self._render(s, i < len(segs) - 1), s[2]) for i, s in enumerate(segs)]
if self.backtick:
pieces.append((BACKTICK, LITERAL))
return pieces
@property
def marked_text(self):
@@ -185,7 +198,7 @@ class CompositionEngine:
def wants(self, key):
"""Whether handle(key) would consume the key, without changing state."""
if self.candidates or key == SHIFT_TAP:
if self.candidates or key == SHIFT_TAP or self.backtick:
return True
if self.english_mode and not self.keys:
return False # English mode: everything goes to the app as typed
@@ -202,6 +215,8 @@ class CompositionEngine:
def handle(self, key):
if self.candidates:
return self._handle_candidate_key(key)
if self.backtick:
return self._after_backtick(key)
if key == BACKSPACE:
if not self.keys:
return PASS
@@ -251,6 +266,19 @@ class CompositionEngine:
return CONSUMED if self.keys else PASS
return self._handle_character(key)
def _after_backtick(self, key):
self.backtick = False
if key in (ESCAPE, BACKSPACE):
return CONSUMED
committed = self._commit() if self.keys else ""
if key in SYMBOLS:
return True, committed + SYMBOLS[key]
# Not a symbol: the backtick was meant literally; then handle the key as usual.
handled, more = self.handle(key)
if not handled and len(key) == 1:
handled, more = True, key
return handled, committed + BACKTICK + (more or "")
def _last_parse(self, segs):
if not segs or segs[-1][2] != ZHUYIN:
return None
@@ -261,6 +289,9 @@ class CompositionEngine:
self.cursor = None # typing always continues at the end
if self.english_mode and not self.keys:
return PASS # English mode: every key goes to the app as typed
if c == BACKTICK:
self.backtick = True
return CONSUMED
if c == " ":
if not self.keys:
return PASS
@@ -356,6 +387,7 @@ class CompositionEngine:
def reset(self):
self.keys = []
self.held = None
self.backtick = False
self.cursor = None
self.forced_mode = None
self.fixed = {}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "自動注音 AutoZhuyin",
"version": "0.6.3",
"version": "0.7.0",
"guid": "{3895C6E3-6D40-4B4B-B4EA-CEEC75382D23}",
"locale": "zh-Hant-TW",
"fallbackLocale": "zh-TW",
+3
View File
@@ -34,6 +34,9 @@
打到一半時按,同 Tab 整段翻轉
Shift+字母 打大寫字母(也會強制英文)
< > ? ! : 中文語境下自動變成全形 ,。?!:
` + 標點 強制全形標點,例如 `< 或 `, = , `. = 。 `/ = ? `; = ;
`' = 、 `[ `] = 「」 `( `) = () `! = !
` 後面接其他鍵就是普通的反引號
注音符號的順序打錯也沒關係,例如 ㄧㄒㄠˇ 會自動變成 ㄒㄧㄠˇ(小)。
+20
View File
@@ -295,5 +295,25 @@ class HeldWordTests(unittest.TestCase):
self.assertEqual(type_keys(" the ", e), "up the ")
class BacktickSymbolTests(unittest.TestCase):
def test_forced_symbols(self):
cases = {"`<": ",", "`.": "。", "`?": "?", "`;": ";", "`[": "「",
"hello`,": "hello,", "su3cl3`.": "你好。", "```\n": "```"}
for keys, want in cases.items():
self.assertEqual(type_keys(keys, make_engine()), want, keys)
def test_plain_backtick(self):
e = make_engine()
self.assertEqual(type_keys("`", e), "")
self.assertEqual(e.marked_text, "`")
self.assertEqual(type_keys("ls` ", e), "`ls` ")
def test_escape_cancels(self):
e = make_engine()
type_keys("su3`", e)
e.handle(BACKSPACE)
self.assertEqual(e.marked_text, "你")
if __name__ == "__main__":
unittest.main()