Skip to content

Commit 1bddd32

Browse files
committed
Megrez // Refactor DropKey; Fix documentation.
1 parent 1b1bdb9 commit 1bddd32

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/Megrez/1_Compositor.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,15 @@ extension Megrez {
167167

168168
/// 朝著指定方向砍掉一個與游標相鄰的讀音。
169169
///
170-
/// 在威注音的術語體系當中,「與文字輸入方向相反的方向」為向後(Rear),反之則為向前(Front)。
170+
/// 在 Megrez 的術語體系當中,「與文字輸入方向相反的方向」為向後(Rear),反之則為向前(Front)。
171171
/// 如果是朝著與文字輸入方向相反的方向砍的話,游標位置會自動遞減。
172172
/// - Parameter direction: 指定方向(相對於文字輸入方向而言)。
173173
/// - Returns: 該操作是否成功執行。
174174
@discardableResult
175175
public func dropKey(direction: TypingDirection) -> Bool {
176+
guard !keys.isEmpty else { return false }
177+
guard !isCursorAtEdge(direction: direction) else { return false }
176178
let isBackSpace: Bool = direction == .rear ? true : false
177-
guard cursor != (isBackSpace ? 0 : keys.count) else { return false }
178179
keys.remove(at: cursor - (isBackSpace ? 1 : 0))
179180
cursor -= isBackSpace ? 1 : 0 // 在縮節之前。
180181
resizeGrid(at: cursor, do: .shrink)
@@ -235,7 +236,7 @@ extension Megrez {
235236

236237
/// 按幅節來前後移動游標。
237238
///
238-
/// 在威注音的術語體系當中,「與文字輸入方向相反的方向」為向後(Rear),反之則為向前(Front)。
239+
/// 在 Megrez 的術語體系當中,「與文字輸入方向相反的方向」為向後(Rear),反之則為向前(Front)。
239240
/// - Parameters:
240241
/// - direction: 指定移動方向(相對於文字輸入方向而言)。
241242
/// - isMarker: 要移動的是否為作為選擇標記的副游標(而非打字用的主游標)。

Sources/Megrez/8_GramInPath.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ extension Array where Element == Megrez.GramInPath {
122122
return !isBound && rawResult
123123
}
124124

125+
/// 偵測游標是否切斷區域。
126+
///
127+
/// 此處不需要針對 cursor 做邊界檢查。
125128
public func isCursorCuttingRegion(cursor: Int) -> Bool {
126129
let index = cursor
127130
var isBound = (index == contextRange(ofGivenCursor: index).lowerBound)

0 commit comments

Comments
 (0)