Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow down the speed of delete word #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cantoboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
7906D6E026D8D35E004C3C0F /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7906D6DF26D8D35E004C3C0F /* UIView+Extension.swift */; };
790839A726D0FCED00CA6B56 /* LocalizedStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 790839A626D0FCED00CA6B56 /* LocalizedStrings.swift */; };
790839B626D1053C00CA6B56 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 790839B826D1053C00CA6B56 /* Localizable.strings */; };
7912CC5A26D2173000BA89AB /* EastAsianWidth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7912CC5926D2173000BA89AB /* EastAsianWidth.swift */; };
7913D968266752FC00DB78C2 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7913D967266752FC00DB78C2 /* main.swift */; };
7917DDA42660A41F00D0010D /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7917DDA32660A41F00D0010D /* GuideViewController.swift */; };
7919A78125F3320F0075DD4D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7919A78025F3320F0075DD4D /* AppDelegate.swift */; };
Expand Down Expand Up @@ -292,7 +291,6 @@
790839C226D105F000CA6B56 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
790839C326D1062F00CA6B56 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "zh-HK.lproj/Localizable.strings"; sourceTree = "<group>"; };
790839C426D1063700CA6B56 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
7912CC5926D2173000BA89AB /* EastAsianWidth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EastAsianWidth.swift; sourceTree = "<group>"; };
7913D965266752FC00DB78C2 /* MissingGlyphRemover */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MissingGlyphRemover; sourceTree = BUILT_PRODUCTS_DIR; };
7913D967266752FC00DB78C2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
7917DDA32660A41F00D0010D /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -566,7 +564,6 @@
isa = PBXGroup;
children = (
79D4E1BE26422C6E00857D7D /* DataFileManager.swift */,
7912CC5926D2173000BA89AB /* EastAsianWidth.swift */,
79BE978426D74B790059E58A /* Extension */,
79D31ACC263FAC1300993949 /* InstanceCounter.swift */,
79515A7D2609AA1500D29A5C /* LevelDbTable.mm */,
Expand Down Expand Up @@ -1293,7 +1290,6 @@
79607A65260FF09200E23D33 /* String+Extension.swift in Sources */,
79B9B5FC25F34A1200238E80 /* Collection+Extension.swift in Sources */,
79B9B5FF25F34A1200238E80 /* UIEdgeInsets+Extension.swift in Sources */,
7912CC5A26D2173000BA89AB /* EastAsianWidth.swift in Sources */,
79B9B5F825F34A1200238E80 /* BilingualInputEngine.swift in Sources */,
79B9B5FB25F34A1200238E80 /* UIColor+Extension.swift in Sources */,
79B9B60925F34A1200238E80 /* LayoutConstants.swift in Sources */,
Expand Down
13 changes: 6 additions & 7 deletions CantoboardFramework/Keyboard/InputController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ class InputController: NSObject {
let lastSymbol = documentContextBeforeInput.last(where: { $0 != " " })
// DDLogInfo("documentContextBeforeInput \(documentContextBeforeInput) \(lastChar)")
let isFirstCharInDoc = lastChar == nil || lastChar == "\n"
let isHalfShapedCase = (lastChar?.isWhitespace ?? false && lastSymbol?.isHalfShapeTerminalPunctuation ?? false)
let isFullShapedCase = lastChar?.isFullShapeTerminalPunctuation ?? false
let isHalfShapedCase = (lastChar?.isWhitespace ?? false && lastSymbol?.isASCIISentenceTerminal ?? false)
let isFullShapedCase = lastChar?.isNonASCIISentenceTerminal ?? false
return isFirstCharInDoc || isHalfShapedCase || isFullShapedCase
}

Expand Down Expand Up @@ -770,8 +770,7 @@ class InputController: NSObject {
let last2CharsInDoc = documentContextBeforeInput.suffix(2)

// Always keep smart space if quotes or non punct symbols are being inserted
if let firstChar = textBeingInserted.first,
firstChar.isOpeningQuote || firstChar.isSymbol && !firstChar.isPunctuation {
if textBeingInserted.first?.shouldKeepSmartSpace ?? false {
return false
}

Expand Down Expand Up @@ -852,12 +851,12 @@ class InputController: NSObject {
var englishWordCount = 0

let lastChar = documentContextBeforeInput.last
let text = (lastChar?.isTerminalPunctuation ?? false) ? documentContextBeforeInput.prefix(documentContextBeforeInput.count - 1) : documentContextBeforeInput[...]
let lastSentenseStartIndex = text.lastIndex(where: { $0.isTerminalPunctuation }) ?? documentContextBeforeInput.startIndex
let text = (lastChar?.isSentenceTerminal ?? false) ? documentContextBeforeInput.prefix(documentContextBeforeInput.count - 1) : documentContextBeforeInput[...]
let lastSentenseStartIndex = text.lastIndex(where: { $0.isSentenceTerminal }) ?? documentContextBeforeInput.startIndex
let lastSentense = documentContextBeforeInput.suffix(from: lastSentenseStartIndex)
var hasStartedEnglishWord = false
for c in lastSentense {
chineseCharCount += c.isChineseChar ? 1 : 0
chineseCharCount += c.isIdeographic ? 1 : 0
if c.isEnglishLetter {
if !hasStartedEnglishWord {
hasStartedEnglishWord = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BilingualInputEngine: InputEngine {

var updateEnglishEngineState = false, updateRimeEngineState = false
queue.async(group: group) {
updateRimeEngineState = self.rimeInputEngine.processChar(char.lowercasedChar)
updateRimeEngineState = self.rimeInputEngine.processChar(char.lowercased().first!)
}
englishInputEngine.textBeforeInput = inputController?.textDocumentProxy?.documentContextBeforeInput
englishInputEngine.textAfterInput = inputController?.textDocumentProxy?.documentContextAfterInput
Expand Down
14 changes: 11 additions & 3 deletions CantoboardFramework/Keyboard/TouchHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ class TouchHandler {
enum InputMode: Equatable {
case typing, backspacing, nextKeyboard, cursorMoving
}
static let keyRepeatInitialDelay = 7 // Unit is keyRepeatInterval
static let keyRepeatInitialDelay = 10 // Unit is keyRepeatInterval
static let longPressDelay = 3
static let keyRepeatInterval = 0.08
static let keyRepeatInterval = 0.05
static let backspaceFrequency = 2
static let deleteWordFrequency = 7
static let deleteWordThreshold = 56
static let cursorMovingStepX: CGFloat = 10
static let initialCursorMovingThreshold = cursorMovingStepX * 1.25
static let swipeXThreshold: CGFloat = 30
Expand Down Expand Up @@ -358,13 +361,18 @@ class TouchHandler {
if touchState.initialAction == .backspace {
guard self.inputMode == .backspacing && keyRepeatCounter > Self.keyRepeatInitialDelay else { continue }
let action: KeyboardAction
if keyRepeatCounter <= 20 {
if keyRepeatCounter < Self.deleteWordThreshold {
guard keyRepeatCounter % Self.backspaceFrequency == 0 else { continue }
action = .backspace
} else {
guard keyRepeatCounter % Self.deleteWordFrequency == 0 else { continue }
action = .deleteWord
}
callKeyHandler(action)
touchState.hasTakenAction = true
if Settings.cached.isTapHapticFeedbackEnabled {
FeedbackProvider.lightImpact.impactOccurred()
}
FeedbackProvider.play(keyboardAction: action)
} else if self.inputMode == .typing && keyRepeatCounter > Self.longPressDelay && !shouldDisableLongPress {
touchState.activeKeyView.keyLongPressed(touchState.touch)
Expand Down
2 changes: 1 addition & 1 deletion CantoboardFramework/Keyboard/View/KeyCap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ enum SpecialSymbol: CaseIterable {
for c in textBefore.reversed() {
if c.isEnglishLetterOrDigit {
return .half
} else if c.isChineseChar {
} else if c.isIdeographic {
return .full
}
}
Expand Down
Loading