Skip to content

Commit

Permalink
Add textControllerDidLayoutText message
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Aug 10, 2016
1 parent 6ad6521 commit fafe110
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Sources/LayoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protocol LayoutManagerDelegate: class {
// as a result changes the text container's geometry).
func layoutManager(layoutManager: NSLayoutManager, textContainerChangedGeometry textContainer: NSTextContainer)
func layoutManagerDidUpdateFolding(layoutManager: NSLayoutManager)
func layoutManagerDidLayout(layoutManager: NSLayoutManager)
}

/// Custom layout manager to handle proper line spacing and folding. This must be its own delegate.
Expand Down Expand Up @@ -146,12 +147,13 @@ class LayoutManager: NSLayoutManager {
// MARK: - Private

private func updateTextContainerIfNeeded() {
guard needsUpdateTextContainer else { return }

textContainers.forEach(ensureLayoutForTextContainer)
layoutDelegate?.layoutManagerDidUpdateFolding(self)
if needsUpdateTextContainer {
textContainers.forEach(ensureLayoutForTextContainer)
layoutDelegate?.layoutManagerDidUpdateFolding(self)
needsUpdateTextContainer = false
}

needsUpdateTextContainer = false
layoutDelegate?.layoutManagerDidLayout(self)
}

private func blockNodeAt(glyphIndex glyphIndex: Int) -> BlockNode? {
Expand Down
5 changes: 5 additions & 0 deletions Sources/TextController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public protocol TextControllerDisplayDelegate: class {
func textControllerDidProcessRemoteEdit(textController: TextController)
func textController(textController: TextController, URLForImage block: CanvasNative.Image) -> NSURL?
func textControllerDidUpdateFolding(textController: TextController)
func textControllerDidLayoutText(textController: TextController)
}

public protocol TextControllerAnnotationDelegate: class {
Expand Down Expand Up @@ -896,4 +897,8 @@ extension TextController: LayoutManagerDelegate {

displayDelegate?.textControllerDidUpdateFolding(self)
}

func layoutManagerDidLayout(layoutManager: NSLayoutManager) {
displayDelegate?.textControllerDidLayoutText(self)
}
}

0 comments on commit fafe110

Please sign in to comment.