Select character in Warnings pane by clicking

This commit is contained in:
1024jp 2022-05-02 20:43:31 +09:00
parent 8cb7f3bc1b
commit d8b078fde9
4 changed files with 57 additions and 16 deletions

View File

@ -15,6 +15,7 @@ Change Log
- [trivial] Enable the secure state restoration instroduced in macOS 12.
- [dev] Update Yams from 5.0.0 to 5.0.1.
- [beta] Add the panel notifying about the line ending migration.
- [beta] Select the character in the editor also when an item already selected in the Warnings pane is clicked.
- [beta][trivial] Rename “Unicode Next Line” to “Next Line”.

View File

@ -183,6 +183,7 @@
</tableColumns>
<connections>
<accessibilityConnection property="title" destination="wLI-76-6zT" id="q4u-TX-zpo"/>
<action selector="selectItem:" target="nX3-cC-y6b" id="wgd-e7-hOe"/>
<outlet property="dataSource" destination="nX3-cC-y6b" id="d3r-Zr-pqk"/>
<outlet property="delegate" destination="nX3-cC-y6b" id="Snk-iF-D9R"/>
</connections>
@ -365,6 +366,7 @@
</tableColumn>
</tableColumns>
<connections>
<action selector="selectItem:" target="tAx-yG-GST" id="yT8-4F-nfd"/>
<outlet property="dataSource" destination="tAx-yG-GST" id="MN2-jP-ese"/>
<outlet property="delegate" destination="tAx-yG-GST" id="Z8D-uT-272"/>
</connections>

View File

@ -131,6 +131,16 @@ final class IncompatibleCharactersViewController: NSViewController {
// MARK: Actions
/// Item in the table was clicked.
@IBAction func selectItem(_ sender: NSTableView) {
self.selectItem(at: sender.clickedRow)
}
// MARK: Private Methods
@MainActor private func didUpdateIncompatibleCharacters(_ incompatibleCharacters: [IncompatibleCharacter]) {
@ -211,6 +221,21 @@ final class IncompatibleCharactersViewController: NSViewController {
}()
}
/// Select correspondence range of the item in the editor.
///
/// - Parameter row: The index of items to select.
@MainActor private func selectItem(at row: Int) {
guard
let item = self.incompatibleCharacters[safe: row],
let textView = self.document?.textView
else { return }
textView.selectedRange = item.range
textView.centerSelectionInVisibleArea(self)
}
}
@ -219,15 +244,9 @@ extension IncompatibleCharactersViewController: NSTableViewDelegate {
func tableViewSelectionDidChange(_ notification: Notification) {
guard
let tableView = notification.object as? NSTableView,
let item = self.incompatibleCharacters[safe: tableView.selectedRow],
let textView = self.document?.textView
else { return }
guard let tableView = notification.object as? NSTableView else { return }
textView.selectedRange = item.range
textView.scrollRangeToVisible(textView.selectedRange)
textView.showFindIndicator(for: textView.selectedRange)
self.selectItem(at: tableView.selectedRow)
}
}

View File

@ -87,6 +87,16 @@ final class InconsistentLineEndingsViewController: NSViewController {
// MARK: Actions
/// Item in the table was clicked.
@IBAction func selectItem(_ sender: NSTableView) {
self.selectItem(at: sender.clickedRow)
}
// MARK: Private Methods
/// Update the result message above the table.
@ -107,6 +117,21 @@ final class InconsistentLineEndingsViewController: NSViewController {
}()
}
/// Select correspondence range of the item in the editor.
///
/// - Parameter row: The index of items to select.
@MainActor private func selectItem(at row: Int) {
guard
let item = self.lineEndings[safe: row],
let textView = self.document?.textView
else { return }
textView.selectedRange = item.range
textView.centerSelectionInVisibleArea(self)
}
}
@ -115,15 +140,9 @@ extension InconsistentLineEndingsViewController: NSTableViewDelegate {
func tableViewSelectionDidChange(_ notification: Notification) {
guard
let tableView = notification.object as? NSTableView,
let selectedLineEnding = self.lineEndings[safe: tableView.selectedRow],
let textView = self.document?.textView
else { return }
guard let tableView = notification.object as? NSTableView else { return }
textView.selectedRange = selectedLineEnding.range
textView.scrollRangeToVisible(textView.selectedRange)
textView.showFindIndicator(for: textView.selectedRange)
self.selectItem(at: tableView.selectedRow)
}
}