Skip to content

Commit

Permalink
fix: 修复在输入过程中,字符会有稍微移动的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyyb committed Oct 28, 2020
1 parent 14c9103 commit d3b71d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Fire/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
InputSource.shared.activateInputSource()
NSApp.terminate(nil)
}

private func commandHandler() {
if CommandLine.arguments.count > 1 {
print("[Fire] launch argument: \(CommandLine.arguments[1])")
Expand Down
1 change: 1 addition & 0 deletions Fire/CandidatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct CandidatesView: View {
})
.padding(.horizontal, 10.0)
.padding(.vertical, 6)
.fixedSize()
.background(Color.white)
}
}
Expand Down
24 changes: 21 additions & 3 deletions Fire/CandidatesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
import SwiftUI
import InputMethodKit

var set = false

class CandidatesWindow: NSWindow {
let hostingView = NSHostingView(rootView: CandidatesView(candidates: [], origin: ""))

func setCandidates(
candidates: [Candidate],
originalString: String,
topLeft: NSPoint
) {
self.contentView = NSHostingView(rootView: CandidatesView(candidates: candidates, origin: originalString))
hostingView.rootView.candidates = candidates
hostingView.rootView.origin = originalString
let origin = self.transformTopLeft(originalTopLeft: topLeft)
self.setFrameTopLeftPoint(origin)
self.orderFront(nil)
Expand All @@ -31,9 +35,23 @@ class CandidatesWindow: NSWindow {
super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)

level = NSWindow.Level(rawValue: NSWindow.Level.RawValue(CGShieldingWindowLevel()))
self.viewsNeedDisplay = true
styleMask = .init(arrayLiteral: .borderless, .fullSizeContentView)
styleMask = .init(arrayLiteral: .fullSizeContentView, .borderless)
isReleasedWhenClosed = false
backgroundColor = NSColor.clear
setSizePolicy()
}

private func setSizePolicy() {
// 窗口大小可根据内容变化
hostingView.translatesAutoresizingMaskIntoConstraints = false
guard self.contentView != nil else {
return
}
self.contentView?.addSubview(hostingView)
self.contentView?.leftAnchor.constraint(equalTo: hostingView.leftAnchor).isActive = true
self.contentView?.rightAnchor.constraint(equalTo: hostingView.rightAnchor).isActive = true
self.contentView?.topAnchor.constraint(equalTo: hostingView.topAnchor).isActive = true
self.contentView?.bottomAnchor.constraint(equalTo: hostingView.bottomAnchor).isActive = true
}

private func transformTopLeft(originalTopLeft: NSPoint) -> NSPoint {
Expand Down

0 comments on commit d3b71d6

Please sign in to comment.