Fix find all result view

This commit is contained in:
1024jp 2016-10-28 01:25:50 +09:00
parent b663070961
commit f86ae78bb0
6 changed files with 12 additions and 21 deletions

View File

@ -18,6 +18,7 @@ develop
### Fixes
- Fix an issue where scripts didn't put results on the document/console.
- Fix an issue where find all results didn't open anymore under the specific conditions.
- Fix an issue where MarsEdit didn't update its contents after closing the document in CotEditor.
- Improve general stability.

View File

@ -98,12 +98,6 @@ final class DocumentWindowController: NSWindowController {
// apply document state to UI
document.applyContentToWindow()
// FIXME: workaround for that contentView origin can stack into toolbar on Sierra (2016-09 on macOS 10.12)
// -> cf. https://github.com/coteditor/CotEditor/issues/600
if let window = self.window {
window.contentView?.frame = window.contentRect(forFrameRect: NSRect(origin: .zero, size: window.frame.size))
}
}
}

View File

@ -93,6 +93,7 @@ final class FindPanelButtonViewController: NSViewController {
case 1:
TextFinder.shared.findNext(sender)
default:
assertionFailure("Number of the find button segments must be 2.")
break
}
}

View File

@ -54,8 +54,6 @@ final class FindPanelContentViewController: NSSplitViewController, TextFinderDel
}
TextFinder.shared.delegate = self
self.setResultShown(false, animate: false)
}
@ -159,15 +157,13 @@ final class FindPanelContentViewController: NSSplitViewController, TextFinderDel
let resultView = resultViewItem.viewController.view
let height = resultView.bounds.height
guard (shown && resultView.isHidden) || (!shown || height <= DefaultResultViewHeight) else { return }
// resize panel frame
let diff: CGFloat = {
if shown {
if resultViewItem.isCollapsed {
return DefaultResultViewHeight
} else {
return DefaultResultViewHeight - height
return max(DefaultResultViewHeight - height, 0)
}
} else {
return -height

View File

@ -40,14 +40,15 @@ final class FindPanelResultViewController: NSViewController, NSTableViewDelegate
// MARK: Public Properties
weak var target: NSTextView? {
// keep TextContainer as `weak` instaed to avoid handling unsafe_unretained TextView
// keep LayoutManager as `weak` instaed to avoid handling unsafe_unretained TextView
get {
return self.layoutManager?.firstTextView
return _layoutManager?.firstTextView
}
set {
self.layoutManager = newValue?.layoutManager
_layoutManager = newValue?.layoutManager
}
}
private weak var _layoutManager: NSLayoutManager?
// MARK: Private Properties
@ -56,8 +57,6 @@ final class FindPanelResultViewController: NSViewController, NSTableViewDelegate
private dynamic var findString: String?
private dynamic var resultMessage: String?
private weak var layoutManager: NSLayoutManager?
@IBOutlet private weak var disclosureButton: NSButton?
@IBOutlet private weak var tableView: NSTableView?

View File

@ -46,7 +46,7 @@ struct TextFindResult {
let range: NSRange
let lineRange: NSRange
let lineNumber: UInt
let lineNumber: Int
let attributedLineString: NSAttributedString
}
@ -290,9 +290,9 @@ final class TextFinder: NSResponder, TextFinderSettingsProvider {
let inlineRange = NSRange(location: matchedRange.location - lineRange.location,
length: matchedRange.length)
let lineString = (string as NSString).substring(with: lineRange)
let lineAttrString = NSMutableAttributedString(string: lineString)
let attrLineString = NSMutableAttributedString(string: lineString)
lineAttrString.addAttribute(NSBackgroundColorAttributeName, value: highlightColors.first!, range: inlineRange)
attrLineString.addAttribute(NSBackgroundColorAttributeName, value: highlightColors.first!, range: inlineRange)
highlights.append(HighlightItem(range: matchedRange, color: highlightColors.first!))
@ -303,12 +303,12 @@ final class TextFinder: NSResponder, TextFinderSettingsProvider {
let color = highlightColors[index]
let inlineRange = NSRange(location: range.location - lineRange.location, length: range.length)
lineAttrString.addAttribute(NSBackgroundColorAttributeName, value: color, range: inlineRange)
attrLineString.addAttribute(NSBackgroundColorAttributeName, value: color, range: inlineRange)
highlights.append(HighlightItem(range: range, color: color))
}
}
results.append(TextFindResult(range: matchedRange, lineRange: inlineRange, lineNumber: UInt(lineNumber), attributedLineString: lineAttrString))
results.append(TextFindResult(range: matchedRange, lineRange: inlineRange, lineNumber: lineNumber, attributedLineString: attrLineString))
// progress indicator
let informativeFormat = (results.count == 1) ? "%@ string found." : "%@ strings found."