mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Obtain visibleRect without additional layout
This commit is contained in:
parent
e6dcabe154
commit
5d5c8d04fa
@ -5,6 +5,11 @@ Change Log
|
||||
3.7.8 (361)
|
||||
--------------------------
|
||||
|
||||
### Improvements
|
||||
|
||||
- Optimize performance of text layout calcuration.
|
||||
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix an issue where the editor could not scroll horizontally under specific conditions.
|
||||
|
@ -38,12 +38,12 @@ extension NSTextView {
|
||||
/// calculate visible range
|
||||
var visibleRange: NSRange? {
|
||||
|
||||
return self.range(for: self.visibleRect)
|
||||
return self.range(for: self.visibleRect, withoutAdditionalLayout: true)
|
||||
}
|
||||
|
||||
|
||||
/// calculate range of characters in rect
|
||||
func range(for rect: NSRect) -> NSRange? {
|
||||
func range(for rect: NSRect, withoutAdditionalLayout: Bool = false) -> NSRange? {
|
||||
|
||||
guard
|
||||
let layoutManager = self.layoutManager,
|
||||
@ -51,7 +51,9 @@ extension NSTextView {
|
||||
else { return nil }
|
||||
|
||||
let visibleRect = rect.offset(by: -self.textContainerOrigin)
|
||||
let glyphRange = layoutManager.glyphRange(forBoundingRect: visibleRect, in: textContainer)
|
||||
let glyphRange = withoutAdditionalLayout
|
||||
? layoutManager.glyphRange(forBoundingRectWithoutAdditionalLayout: visibleRect, in: textContainer)
|
||||
: layoutManager.glyphRange(forBoundingRect: visibleRect, in: textContainer)
|
||||
|
||||
return layoutManager.characterRange(forGlyphRange: glyphRange, actualGlyphRange: nil)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// © 2018 1024jp
|
||||
// © 2018-2019 1024jp
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -41,7 +41,7 @@ extension NSTextView {
|
||||
// avoid invoking heavy-duty `range(for:)` as possible
|
||||
guard
|
||||
let layoutManager = self.layoutManager,
|
||||
let dirtyRange = self.range(for: dirtyRect),
|
||||
let dirtyRange = self.range(for: dirtyRect, withoutAdditionalLayout: true),
|
||||
layoutManager.hasTemporaryAttribute(for: .roundedBackgroundColor, in: dirtyRange)
|
||||
else { return }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user