Skip to content

Commit

Permalink
Merge pull request #31 from mtgto/fix-inline-candidate-panel
Browse files Browse the repository at this point in the history
インライン注釈が表示されたあと次の候補が注釈がないときに空パネルが残るバグを修正
  • Loading branch information
mtgto authored Sep 10, 2023
2 parents 965fc06 + b8b76f8 commit 867cc2f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
12 changes: 12 additions & 0 deletions macSKK/AnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@ struct AnnotationView_Previews: PreviewProvider {
)
.frame(width: 300)
.previewDisplayName("SKK辞書の注釈 & システム辞書の注釈")
AnnotationView(
annotations: .constant([]),
systemAnnotation: .constant(String(repeating: "これはシステム辞書の注釈です。", count: 10))
)
.frame(width: 300)
.previewDisplayName("システム辞書のみ")
AnnotationView(
annotations: .constant([]),
systemAnnotation: .constant(nil)
)
.frame(width: 300)
.previewDisplayName("注釈なし")
}
}
2 changes: 1 addition & 1 deletion macSKK/CandidatesPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class CandidatesPanel: NSPanel {
}

func setSystemAnnotation(_ systemAnnotation: String, for word: Word.Word) {
viewModel.systemAnnotations.updateValue(systemAnnotation, forKey: word)
viewModel.systemAnnotations[word] = systemAnnotation
}

func setCursorPosition(_ cursorPosition: NSRect) {
Expand Down
19 changes: 17 additions & 2 deletions macSKK/CandidatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,25 @@ struct CandidatesView_Previews: PreviewProvider {
annotations: [Annotation(dictId: "SKK-JISYO.L", text: "注釈\($0)")])
}

static var previews: some View {
private static func pageViewModel() -> CandidatesViewModel {
let viewModel = CandidatesViewModel(candidates: words, currentPage: 0, totalPageCount: 3)
viewModel.selected = words.first
viewModel.systemAnnotations = [words.first!.word: String(repeating: "これはシステム辞書の注釈です。", count: 10)]
return CandidatesView(candidates: viewModel)
return viewModel
}

private static func inlineViewModel() -> CandidatesViewModel {
let viewModel = CandidatesViewModel(candidates: words, currentPage: 0, totalPageCount: 3)
viewModel.candidates = .inline
viewModel.selected = words.first
viewModel.systemAnnotations = [words.first!.word: String(repeating: "これはシステム辞書の注釈です。", count: 10)]
return viewModel
}

static var previews: some View {
CandidatesView(candidates: pageViewModel())
.previewDisplayName("パネル表示")
CandidatesView(candidates: inlineViewModel())
.previewDisplayName("インライン表示")
}
}
9 changes: 4 additions & 5 deletions macSKK/InputController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ class InputController: IMKInputController {
currentPage: page.current,
totalPageCount: page.total)
self?.candidatesPanel.setCandidates(currentCandidates, selected: candidates.selected)
self?.selectedWord.send(candidates.selected.word)
self?.candidatesPanel.show()
} else {
self?.candidatesPanel.setCandidates(.inline, selected: candidates.selected)
self?.selectedWord.send(candidates.selected.word)
if !candidates.selected.annotations.isEmpty {
self?.candidatesPanel.setCandidates(.inline, selected: candidates.selected)
if candidates.selected.annotations.isEmpty {
self?.candidatesPanel.orderOut(nil)
} else {
self?.candidatesPanel.show()
}
self?.candidatesPanel.setCandidates(.inline, selected: candidates.selected)
}
} else {
// 変換→キャンセル→再変換しても注釈が表示されなくならないように状態を変えておく
Expand Down
3 changes: 3 additions & 0 deletions macSKK/macSKKApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ struct macSKKApp: App {
candidatesPanel.setCursorPosition(NSRect(origin: NSPoint(x: 100, y: 640), size: CGSize(width: 0, height: 30)))
candidatesPanel.show()
}
Button("Hide AnnotataionsPanel") {
candidatesPanel.orderOut(nil)
}
Button("SystemAnnotation") {
candidatesPanel.viewModel.systemAnnotations = ["インライン": (String(repeating: "これはシステム辞書の注釈です。", count: 5))]
}
Expand Down

0 comments on commit 867cc2f

Please sign in to comment.