aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa/ScintillaCocoa.mm
diff options
context:
space:
mode:
Diffstat (limited to 'cocoa/ScintillaCocoa.mm')
-rw-r--r--cocoa/ScintillaCocoa.mm59
1 files changed, 59 insertions, 0 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index fe12690a4..8a31b40d3 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -383,6 +383,7 @@ ScintillaCocoa::ScintillaCocoa(NSView* view)
{
wMain = view; // Don't retain since we're owned by view, which would cause a cycle
timerTarget = [[TimerTarget alloc] init: this];
+ observer = NULL;
layerFindIndicator = NULL;
Initialise();
}
@@ -428,12 +429,70 @@ void ScintillaCocoa::Initialise()
*/
void ScintillaCocoa::Finalise()
{
+ ObserverRemove();
SetTicking(false);
ScintillaBase::Finalise();
}
//--------------------------------------------------------------------------------------------------
+void ScintillaCocoa::UpdateObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
+ ScintillaCocoa* sci = reinterpret_cast<ScintillaCocoa*>(info);
+ sci->IdleWork();
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
+ * Add an observer to the run loop to perform styling as high-priority idle task.
+ */
+
+void ScintillaCocoa::ObserverAdd() {
+ if (!observer) {
+ CFRunLoopObserverContext context;
+ context.version = 0;
+ context.info = this;
+ context.retain = NULL;
+ context.release = NULL;
+ context.copyDescription = NULL;
+
+ CFRunLoopRef mainRunLoop = CFRunLoopGetMain();
+ observer = CFRunLoopObserverCreate(NULL, kCFRunLoopEntry | kCFRunLoopBeforeWaiting,
+ true, 0, UpdateObserver, &context);
+ CFRunLoopAddObserver(mainRunLoop, observer, kCFRunLoopCommonModes);
+ }
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
+ * Remove the run loop observer.
+ */
+void ScintillaCocoa::ObserverRemove() {
+ if (observer) {
+ CFRunLoopRef mainRunLoop = CFRunLoopGetMain();
+ CFRunLoopRemoveObserver(mainRunLoop, observer, kCFRunLoopCommonModes);
+ CFRelease(observer);
+ }
+ observer = NULL;
+}
+
+//--------------------------------------------------------------------------------------------------
+
+void ScintillaCocoa::IdleWork() {
+ Editor::IdleWork();
+ ObserverRemove();
+}
+
+//--------------------------------------------------------------------------------------------------
+
+void ScintillaCocoa::QueueIdleWork(WorkNeeded::workItems items, int upTo) {
+ Editor::QueueIdleWork(items, upTo);
+ ObserverAdd();
+}
+
+//--------------------------------------------------------------------------------------------------
+
/**
* Convert a core foundation string into an array of bytes in a particular encoding
*/