Fixes duplicated code and typos.
This commit is contained in:
parent
11d33c0b42
commit
f339948219
|
@ -1,4 +1,5 @@
|
||||||
build
|
build
|
||||||
|
.build
|
||||||
*.pbxuser
|
*.pbxuser
|
||||||
*.mode1v3
|
*.mode1v3
|
||||||
*.tm_build_errors
|
*.tm_build_errors
|
||||||
|
|
|
@ -312,9 +312,9 @@ public class HorizontalCandidateController : CandidateController {
|
||||||
return result < delegate.candidateCountForController(self) ? result : UInt.max
|
return result < delegate.candidateCountForController(self) ? result : UInt.max
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public override var selectedCandidateIndex: UInt {
|
public override var selectedCandidateIndex: UInt {
|
||||||
get {
|
get {
|
||||||
return currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex
|
currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
guard let delegate = delegate else {
|
guard let delegate = delegate else {
|
||||||
|
@ -362,7 +362,7 @@ extension HorizontalCandidateController {
|
||||||
frameRect.size = newSize
|
frameRect.size = newSize
|
||||||
candidateView.frame = frameRect
|
candidateView.frame = frameRect
|
||||||
|
|
||||||
if self.pageCount > 1 {
|
if pageCount > 1 {
|
||||||
var buttonRect = nextPageButton.frame
|
var buttonRect = nextPageButton.frame
|
||||||
var spacing = 0.0
|
var spacing = 0.0
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ extension HorizontalCandidateController {
|
||||||
frameRect.size = newSize
|
frameRect.size = newSize
|
||||||
frameRect.origin = NSMakePoint(topLeftPoint.x, topLeftPoint.y - frameRect.size.height)
|
frameRect.origin = NSMakePoint(topLeftPoint.x, topLeftPoint.y - frameRect.size.height)
|
||||||
self.window?.setFrame(frameRect, display: false)
|
self.window?.setFrame(frameRect, display: false)
|
||||||
self.candidateView.setNeedsDisplay(candidateView.bounds)
|
candidateView.setNeedsDisplay(candidateView.bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func pageButtonAction(_ sender: Any) {
|
@objc fileprivate func pageButtonAction(_ sender: Any) {
|
||||||
|
@ -412,7 +412,7 @@ extension HorizontalCandidateController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func candidateViewMouseDidClick(_ sender: Any) {
|
@objc fileprivate func candidateViewMouseDidClick(_ sender: Any) {
|
||||||
delegate?.candidateController(self, didSelectCandidateAtIndex: self.selectedCandidateIndex)
|
delegate?.candidateController(self, didSelectCandidateAtIndex: selectedCandidateIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class VerticalCandidateController: CandidateController {
|
||||||
public override func reloadData() {
|
public override func reloadData() {
|
||||||
maxCandidateAttrStringWidth = ceil(candidateFont.pointSize * 2.0 + candidateTextPadding)
|
maxCandidateAttrStringWidth = ceil(candidateFont.pointSize * 2.0 + candidateTextPadding)
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
self.layoutCandidateView()
|
layoutCandidateView()
|
||||||
if delegate?.candidateCountForController(self) ?? 0 > 0 {
|
if delegate?.candidateCountForController(self) ?? 0 > 0 {
|
||||||
selectedCandidateIndex = 0
|
selectedCandidateIndex = 0
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ public class VerticalCandidateController: CandidateController {
|
||||||
return UInt.max
|
return UInt.max
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public override var selectedCandidateIndex: UInt {
|
public override var selectedCandidateIndex: UInt {
|
||||||
get {
|
get {
|
||||||
let selectedRow = tableView.selectedRow
|
let selectedRow = tableView.selectedRow
|
||||||
return selectedRow == -1 ? UInt.max : UInt(selectedRow)
|
return selectedRow == -1 ? UInt.max : UInt(selectedRow)
|
||||||
|
@ -390,11 +390,11 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
||||||
|
|
||||||
private func layoutCandidateView() {
|
private func layoutCandidateView() {
|
||||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { [self] in
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { [self] in
|
||||||
self.doLayoutCanaditeView()
|
doLayoutCandidateView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func doLayoutCanaditeView() {
|
private func doLayoutCandidateView() {
|
||||||
guard let delegate = delegate else {
|
guard let delegate = delegate else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
// a special deferred client for Terminal.app fix
|
// a special deferred client for Terminal.app fix
|
||||||
id _currentDeferredClient;
|
id _currentDeferredClient;
|
||||||
|
|
||||||
// currently available candidates
|
// current available candidates
|
||||||
NSMutableArray *_candidates;
|
NSMutableArray *_candidates;
|
||||||
|
|
||||||
// current input mode
|
// current input mode
|
||||||
|
|
|
@ -1140,6 +1140,31 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
string layout = [self currentLayout];
|
string layout = [self currentLayout];
|
||||||
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode);
|
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode);
|
||||||
if (_languageModel->hasUnigramsForKey(customPunctuation)) {
|
if (_languageModel->hasUnigramsForKey(customPunctuation)) {
|
||||||
|
[self handlePunctuation:customPunctuation usingVerticalMode:useVerticalMode client:client];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if nothing is matched, see if it's a punctuation key
|
||||||
|
string punctuation = string("_punctuation_") + string(1, (char)charCode);
|
||||||
|
if (_languageModel->hasUnigramsForKey(punctuation)) {
|
||||||
|
[self handlePunctuation:punctuation usingVerticalMode:useVerticalMode client:client];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// still nothing, then we update the composing buffer (some app has
|
||||||
|
// strange behavior if we don't do this, "thinking" the key is not
|
||||||
|
// actually consumed)
|
||||||
|
if ([_composingBuffer length] || !_bpmfReadingBuffer->isEmpty()) {
|
||||||
|
[self beep];
|
||||||
|
[self updateClientComposingBuffer:client];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)handlePunctuation:(string)customPunctuation usingVerticalMode:(BOOL)useVerticalMode client:(id)client
|
||||||
|
{
|
||||||
if (_bpmfReadingBuffer->isEmpty()) {
|
if (_bpmfReadingBuffer->isEmpty()) {
|
||||||
_builder->insertReadingAtCursor(customPunctuation);
|
_builder->insertReadingAtCursor(customPunctuation);
|
||||||
[self popOverflowComposingTextAndWalk:client];
|
[self popOverflowComposingTextAndWalk:client];
|
||||||
|
@ -1158,45 +1183,6 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if nothing is matched, see if it's a punctuation key
|
|
||||||
string punctuation = string("_punctuation_") + string(1, (char)charCode);
|
|
||||||
if (_languageModel->hasUnigramsForKey(punctuation)) {
|
|
||||||
if (_bpmfReadingBuffer->isEmpty()) {
|
|
||||||
_builder->insertReadingAtCursor(punctuation);
|
|
||||||
[self popOverflowComposingTextAndWalk:client];
|
|
||||||
}
|
|
||||||
else { // If there is still unfinished bpmf reading, ignore the punctuation
|
|
||||||
[self beep];
|
|
||||||
}
|
|
||||||
[self updateClientComposingBuffer:client];
|
|
||||||
|
|
||||||
if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) {
|
|
||||||
[self collectCandidates];
|
|
||||||
if ([_candidates count] == 1) {
|
|
||||||
[self commitComposition:client];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// still nothing, then we update the composing buffer (some app has
|
|
||||||
// strange behavior if we don't do this, "thinking" the key is not
|
|
||||||
// actually consumed)
|
|
||||||
if ([_composingBuffer length] || !_bpmfReadingBuffer->isEmpty()) {
|
|
||||||
[self beep];
|
|
||||||
[self updateClientComposingBuffer:client];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class InputSourceHelper: NSObject {
|
||||||
public static func inputSource(for propertyKey: CFString, stringValue: String) -> TISInputSource? {
|
public static func inputSource(for propertyKey: CFString, stringValue: String) -> TISInputSource? {
|
||||||
let stringID = CFStringGetTypeID()
|
let stringID = CFStringGetTypeID()
|
||||||
for source in allInstalledInputSources() {
|
for source in allInstalledInputSources() {
|
||||||
if let proprtyPtr = TISGetInputSourceProperty(source, propertyKey) {
|
if let propertyPtr = TISGetInputSourceProperty(source, propertyKey) {
|
||||||
let property = Unmanaged<CFTypeRef>.fromOpaque(proprtyPtr).takeUnretainedValue()
|
let property = Unmanaged<CFTypeRef>.fromOpaque(propertyPtr).takeUnretainedValue()
|
||||||
let typeID = CFGetTypeID(property)
|
let typeID = CFGetTypeID(property)
|
||||||
if typeID != stringID {
|
if typeID != stringID {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -40,7 +40,8 @@ import Cocoa
|
||||||
}
|
}
|
||||||
|
|
||||||
class NonModalAlertWindowController: NSWindowController {
|
class NonModalAlertWindowController: NSWindowController {
|
||||||
@objc(sharedInstance) static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController")
|
@objc (sharedInstance)
|
||||||
|
static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController")
|
||||||
|
|
||||||
@IBOutlet weak var titleTextField: NSTextField!
|
@IBOutlet weak var titleTextField: NSTextField!
|
||||||
@IBOutlet weak var contentTextField: NSTextField!
|
@IBOutlet weak var contentTextField: NSTextField!
|
||||||
|
@ -62,7 +63,7 @@ class NonModalAlertWindowController: NSWindowController {
|
||||||
var newFrame = confirmButton.frame
|
var newFrame = confirmButton.frame
|
||||||
newFrame.size.width = max(90, newFrame.size.width + 10)
|
newFrame.size.width = max(90, newFrame.size.width + 10)
|
||||||
newFrame.origin.x += oldFrame.size.width - newFrame.size.width
|
newFrame.origin.x += oldFrame.size.width - newFrame.size.width
|
||||||
self.confirmButton.frame = newFrame
|
confirmButton.frame = newFrame
|
||||||
|
|
||||||
if let cancelButtonTitle = cancelButtonTitle {
|
if let cancelButtonTitle = cancelButtonTitle {
|
||||||
cancelButton.title = cancelButtonTitle
|
cancelButton.title = cancelButtonTitle
|
||||||
|
@ -70,10 +71,10 @@ class NonModalAlertWindowController: NSWindowController {
|
||||||
var adjustFrame = cancelButton.frame
|
var adjustFrame = cancelButton.frame
|
||||||
adjustFrame.size.width = max(90, adjustFrame.size.width + 10)
|
adjustFrame.size.width = max(90, adjustFrame.size.width + 10)
|
||||||
adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width
|
adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width
|
||||||
self.confirmButton.frame = adjustFrame
|
confirmButton.frame = adjustFrame
|
||||||
self.cancelButton.isHidden = false
|
cancelButton.isHidden = false
|
||||||
} else {
|
} else {
|
||||||
self.cancelButton.isHidden = true
|
cancelButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelButton.nextKeyView = confirmButton
|
cancelButton.nextKeyView = confirmButton
|
||||||
|
|
|
@ -13,10 +13,10 @@ class OpenCCBridge: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc static func convert(_ string: String) -> String? {
|
@objc static func convert(_ string: String) -> String? {
|
||||||
return shared.converter?.convert(string)
|
shared.converter?.convert(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func convert(_ string: String) -> String? {
|
private func convert(_ string: String) -> String? {
|
||||||
return converter?.convert(string)
|
converter?.convert(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue