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

fix(view): 修复输入时弹窗会超出屏幕的问题 #28

Merged
merged 1 commit into from
Oct 30, 2020
Merged
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
12 changes: 9 additions & 3 deletions Fire/CandidatesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import InputMethodKit

var set = false

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

func windowDidResize(_ notification: Notification) {
// 窗口大小变化时,确保不会超出当前屏幕范围
let origin = self.transformTopLeft(originalTopLeft: NSPoint(x: self.frame.minX, y: self.frame.maxY))
self.setFrameTopLeftPoint(origin)
}

func setCandidates(
candidates: [Candidate],
originalString: String,
topLeft: NSPoint
) {
hostingView.rootView.candidates = candidates
hostingView.rootView.origin = originalString
let origin = self.transformTopLeft(originalTopLeft: topLeft)
self.setFrameTopLeftPoint(origin)
self.setFrameTopLeftPoint(topLeft)
self.orderFront(nil)
}

Expand All @@ -38,6 +43,7 @@ class CandidatesWindow: NSWindow {
styleMask = .init(arrayLiteral: .fullSizeContentView, .borderless)
isReleasedWhenClosed = false
backgroundColor = NSColor.clear
delegate = self
setSizePolicy()
}

Expand Down