Pre Merge pull request !44 from ShikiSuen/upd/1.7.0sp1

This commit is contained in:
ShikiSuen 2022-06-07 16:35:33 +00:00 committed by Gitee
commit 81f83ecb35
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 52 additions and 122 deletions

View File

@ -2,7 +2,7 @@ $ Main contributors and volunteers of this repository (vChewing for macOS):
- Shiki Suen // Main developer of vChewing for macOS, Megrez language engine, and Tekkon syllable composer engine.
- Hiraku Wang // Technical reinforcement in Cocoa during the Object-Cpp dev period of this project.
- Isaac Xen // Technical reinforcement in Swift: SFX Module and StringView Ranges Extension.
- Isaac Xen // Technical reinforcement in Swift: SFX Module (NSSound ver.) and StringView Ranges Extension.
$ Contributors and volunteeres of the upstream repo, having no responsibility in discussing anything in the current repo:

@ -1 +1 @@
Subproject commit 06d16d8a468668278ad9f50cc8629983c490fa42
Subproject commit 01adac46a15ab0bf907ca1bd362bdd1082e79c4e

View File

@ -162,36 +162,38 @@ class KeyHandler {
func fixNode(value: String, respectCursorPushing: Bool = true) {
let cursorIndex = min(actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), builderLength)
let selectedNode: Megrez.NodeAnchor = _builder.grid.fixNodeSelectedCandidate(
location: cursorIndex, value: value
)
//
if !mgrPrefs.useSCPCTypingMode {
// If the length of the readings and the characters do not match,
// it often means it is a special symbol and it should not be stored
// in the user override model.
var addToUserOverrideModel = true
if selectedNode.spanningLength != value.count {
IME.prtDebugIntel("UOM: SpanningLength != value.count, dismissing.")
addToUserOverrideModel = false
}
if addToUserOverrideModel {
if let theNode = selectedNode.node {
// SymbolLM Score -12
if theNode.scoreFor(candidate: value) <= -12 {
IME.prtDebugIntel("UOM: Score <= -12, dismissing.")
addToUserOverrideModel = false
}
}
}
if addToUserOverrideModel {
IME.prtDebugIntel("UOM: Start Observation.")
_userOverrideModel.observe(
walkedNodes: _walkedNodes, cursorIndex: cursorIndex, candidate: value,
timestamp: NSDate().timeIntervalSince1970
)
}
}
_builder.grid.fixNodeSelectedCandidate(location: cursorIndex, value: value)
// //
// let selectedNode: Megrez.NodeAnchor = _builder.grid.fixNodeSelectedCandidate(
// location: cursorIndex, value: value
// )
// //
// if !mgrPrefs.useSCPCTypingMode {
// // If the length of the readings and the characters do not match,
// // it often means it is a special symbol and it should not be stored
// // in the user override model.
// var addToUserOverrideModel = true
// if selectedNode.spanningLength != value.count {
// IME.prtDebugIntel("UOM: SpanningLength != value.count, dismissing.")
// addToUserOverrideModel = false
// }
// if addToUserOverrideModel {
// if let theNode = selectedNode.node {
// // SymbolLM Score -12
// if theNode.scoreFor(candidate: value) <= -12 {
// IME.prtDebugIntel("UOM: Score <= -12, dismissing.")
// addToUserOverrideModel = false
// }
// }
// }
// if addToUserOverrideModel {
// IME.prtDebugIntel("UOM: Start Observation.")
// _userOverrideModel.observe(
// walkedNodes: _walkedNodes, cursorIndex: cursorIndex, candidate: value,
// timestamp: NSDate().timeIntervalSince1970
// )
// }
// }
walk()
if mgrPrefs.moveCursorAfterSelectingCandidate, respectCursorPushing {

View File

@ -188,7 +188,7 @@ extension KeyHandler {
let poppedText = popOverflowComposingTextAndWalk
// ... get and tweak override model suggestion if possible...
dealWithOverrideModelSuggestions()
// dealWithOverrideModelSuggestions() // 使
// ... then update the text.
_composer.clear()

View File

@ -1,6 +1,4 @@
// Copyright (c) 2022 and onwards Isaac Xen (MIT License).
// All possible vChewing-specific modifications are of:
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
// Copyright (c) 2021 and onwards The vChewing Project (MIT-NTL License).
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@ -24,52 +22,15 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import Cocoa
public class clsSFX: NSObject, NSSoundDelegate {
private static let shared = clsSFX()
override private init() {
super.init()
}
private var currentBeep: NSSound?
private func beep() {
let defaultVolume: Float = 0.4
// Stop existing beep
if let beep = currentBeep {
if beep.isPlaying {
for i in 1..<30 {
beep.volume = (defaultVolume / Float(i))
usleep(1000)
}
beep.stop()
beep.volume = defaultVolume
}
}
// Create a new beep sound if possible
var sndBeep: String
if mgrPrefs.shouldNotFartInLieuOfBeep == false {
sndBeep = "Fart"
} else {
sndBeep = "Beep"
}
guard
let beep = NSSound(named: sndBeep)
else {
NSSound.beep()
return
}
beep.delegate = self
beep.volume = defaultVolume
beep.play()
currentBeep = beep
}
public func sound(_: NSSound, didFinishPlaying _: Bool) {
currentBeep = nil
}
import AVFoundation
import Foundation
public class clsSFX {
static func beep() {
shared.beep()
let filePath = Bundle.main.path(forResource: mgrPrefs.shouldNotFartInLieuOfBeep ? "Beep" : "Fart", ofType: "m4a")!
let fileURL = URL(fileURLWithPath: filePath)
var soundID: SystemSoundID = 0
AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID)
AudioServicesPlaySystemSound(soundID)
}
}

Binary file not shown.

Binary file not shown.

View File

@ -409,8 +409,6 @@ public class ctlCandidateUniversal: ctlCandidate {
let buttonAttribute: [NSAttributedString.Key: Any] = [.font: NSFont.systemFont(ofSize: 9.0)]
nextPageButton = .init(frame: contentRect)
NSColor.controlBackgroundColor.setFill()
NSBezierPath.fill(nextPageButton.bounds)
nextPageButton.wantsLayer = true
nextPageButton.layer?.masksToBounds = true
nextPageButton.layer?.borderColor = NSColor.clear.cgColor
@ -422,8 +420,6 @@ public class ctlCandidateUniversal: ctlCandidate {
string: " ", attributes: buttonAttribute
) // Next Page Arrow
prevPageButton = .init(frame: contentRect)
NSColor.controlBackgroundColor.setFill()
NSBezierPath.fill(prevPageButton.bounds)
prevPageButton.wantsLayer = true
prevPageButton.layer?.masksToBounds = true
prevPageButton.layer?.borderColor = NSColor.clear.cgColor
@ -439,17 +435,13 @@ public class ctlCandidateUniversal: ctlCandidate {
// MARK: Add Page Counter
contentRect.size = NSSize(width: 40.0, height: 20.0)
contentRect = NSRect(x: 128.0, y: 128.0, width: 48.0, height: 20.0)
pageCounterLabel = .init(frame: contentRect)
pageCounterLabel.isEditable = false
pageCounterLabel.isSelectable = false
pageCounterLabel.isBezeled = false
pageCounterLabel.textColor = NSColor(
red: 0.86, green: 0.86, blue: 0.86, alpha: 1.00
)
pageCounterLabel.drawsBackground = true
pageCounterLabel.backgroundColor = NSColor(
red: 0.18, green: 0.18, blue: 0.18, alpha: 1.00
pageCounterLabel.attributedStringValue = NSMutableAttributedString(
string: " ", attributes: buttonAttribute
)
panel.contentView?.addSubview(pageCounterLabel)
@ -466,8 +458,6 @@ public class ctlCandidateUniversal: ctlCandidate {
prevPageButton.target = self
prevPageButton.action = #selector(pageButtonAction(_:))
pageCounterLabel.font = pageCounterFont
}
@available(*, unavailable)
@ -554,30 +544,6 @@ extension ctlCandidateUniversal {
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
}
// NSFont nil guard-let
private var pageCounterFont: NSFont? {
var pointSize: CGFloat { candidateView.fractionFontSize }
let systemFontDesc = NSFont.systemFont(ofSize: pointSize, weight: .light).fontDescriptor
let fractionFontDesc = systemFontDesc.addingAttributes(
[
NSFontDescriptor.AttributeName.traits: [
[
NSFontDescriptor.FeatureKey.typeIdentifier: kFractionsType,
NSFontDescriptor.FeatureKey.selectorIdentifier: kDiagonalFractionsSelector,
]
]
]
)
return NSFont(descriptor: fractionFontDesc, size: pointSize) ?? nil
}
//
// TODO: pageCount 調
private var pageCounterText: String {
if pageCount < 2 { return .init() }
return "\(currentPageIndex + 1)/"
}
private func layoutCandidateView() {
guard let delegate = delegate else {
return
@ -627,11 +593,11 @@ extension ctlCandidateUniversal {
prevPageButton.isHidden = true
}
if !pageCounterText.isEmpty {
let attrString = NSAttributedString(
string: pageCounterText.appending(String(pageCount)),
if pageCount >= 2 {
let attrString = NSMutableAttributedString(
string: "\(currentPageIndex + 1)/\(pageCount)",
attributes: [
.font: pageCounterFont as AnyObject
.font: NSFont.systemFont(ofSize: candidateView.fractionFontSize)
]
)
pageCounterLabel.attributedStringValue = attrString
@ -641,6 +607,7 @@ extension ctlCandidateUniversal {
)
rect.size.height += 3
rect.size.width += 4
let rectOriginY: CGFloat =
(currentLayout == .horizontal)
? (newSize.height - rect.height) / 2