Disable noncontiguous layout in normal-size documents (close #876)

This commit is contained in:
1024jp 2018-12-06 15:56:13 +09:00
parent 18da3c5c21
commit 4caccbcc7a
4 changed files with 20 additions and 4 deletions

View File

@ -15,6 +15,8 @@ Change Log
- Improve the performance of text replacement significantly.
- Improve the line number view fundamentally so that all unwanted behaviors after macOS Mojave disappear.
- Select the setting selected in the last session when opening the Multiple Replacement window.
- Enable the noncontiguous layout only with large documents.
- This change may improve the editor's dwaring and scrolling behaviors.
- Improve general performance and stability.
- [dev] Stop LineNumberView inheriting NSRulerView.

View File

@ -178,6 +178,7 @@ extension DefaultKeys {
static let enableSmartIndent = DefaultKey<Bool>("enableSmartIndent")
static let maximumRecentStyleCount = DefaultKey<Int>("maximumRecentStyleCount")
static let maximumSelectionInstanceHighlightCount = DefaultKey<Int>("maximumSelectionInstanceHighlightCount")
static let minimumLengthForNonContiguousLayout = DefaultKey<Int>("minimumLengthForNonContiguousLayout")
static let lastVersion = DefaultKey<String>("lastVersion")

View File

@ -186,6 +186,7 @@ struct DefaultSettings {
.enableSmartIndent: true,
.maximumRecentStyleCount: 6,
.maximumSelectionInstanceHighlightCount: 100,
.minimumLengthForNonContiguousLayout: 5_000_000,
]

View File

@ -126,7 +126,6 @@ final class EditorTextView: NSTextView, CurrentLineHighlighting, Themable {
// setup layoutManager and textContainer
let layoutManager = LayoutManager()
layoutManager.allowsNonContiguousLayout = true
self.textContainer!.replaceLayoutManager(layoutManager)
// set layout values
@ -297,6 +296,8 @@ final class EditorTextView: NSTextView, CurrentLineHighlighting, Themable {
super.didChangeText()
self.invalidateNonContiguousLayout()
self.needsUpdateLineHighlight = true
// retry completion if needed
@ -805,9 +806,7 @@ final class EditorTextView: NSTextView, CurrentLineHighlighting, Themable {
super.setLayoutOrientation(orientation)
self.didChangeValue(forKey: #keyPath(layoutOrientation))
// enable noncontiguous layout only on normal horizontal layout (2016-06 on OS X 10.11 El Capitan)
// -> Otherwise by vertical layout, the view scrolls occasionally to a strange position on typing.
self.layoutManager?.allowsNonContiguousLayout = (orientation == .horizontal)
self.invalidateNonContiguousLayout()
// reset writing direction
if orientation == .vertical {
@ -1321,6 +1320,19 @@ final class EditorTextView: NSTextView, CurrentLineHighlighting, Themable {
}
/// validate whether turns the noncontiguous layout on
private func invalidateNonContiguousLayout() {
let isLargeText = self.string.count > UserDefaults.standard[.minimumLengthForNonContiguousLayout]
// enable noncontiguous layout only on normal horizontal layout (2016-06 on OS X 10.11 El Capitan)
// -> Otherwise by vertical layout, the view scrolls occasionally to a strange position on typing.
let isHorizontal = (self.layoutOrientation == .horizontal)
self.layoutManager?.allowsNonContiguousLayout = isLargeText && isHorizontal
}
/// use legible white-based custom i-beam cursor for dark theme
private func invalidateCursor() {