diff options
-rw-r--r-- | gtk/ScintillaGTK.cxx | 10 | ||||
-rw-r--r-- | src/Editor.cxx | 21 | ||||
-rw-r--r-- | src/Editor.h | 23 |
3 files changed, 31 insertions, 23 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 729db64ee..6b2e15e10 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -296,7 +296,7 @@ private: static gboolean TimeOut(ScintillaGTK *sciThis); static gboolean IdleCallback(ScintillaGTK *sciThis); static gboolean StyleIdle(ScintillaGTK *sciThis); - virtual void QueueStyling(int upTo); + virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo); static void PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis); #if GTK_CHECK_VERSION(3,0,0) @@ -2768,11 +2768,11 @@ gboolean ScintillaGTK::StyleIdle(ScintillaGTK *sciThis) { return FALSE; } -void ScintillaGTK::QueueStyling(int upTo) { - Editor::QueueStyling(upTo); - if (!styleNeeded.active) { +void ScintillaGTK::QueueIdleWork(WorkNeeded::workItems items, int upTo) { + Editor::QueueIdleWork(items, upTo); + if (!workNeeded.active) { // Only allow one style needed to be queued - styleNeeded.active = true; + workNeeded.active = true; g_idle_add_full(G_PRIORITY_HIGH_IDLE, reinterpret_cast<GSourceFunc>(StyleIdle), this, NULL); } diff --git a/src/Editor.cxx b/src/Editor.cxx index 5ce531787..f2a6a1f62 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -782,6 +782,7 @@ void Editor::SetSelection(SelectionPosition currentPos_, SelectionPosition ancho if (highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } + QueueIdleWork(WorkNeeded::workUpdateUI); } void Editor::SetSelection(int currentPos_, int anchor_) { @@ -808,6 +809,7 @@ void Editor::SetSelection(SelectionPosition currentPos_) { if (highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } + QueueIdleWork(WorkNeeded::workUpdateUI); } void Editor::SetSelection(int currentPos_) { @@ -828,6 +830,7 @@ void Editor::SetEmptySelection(SelectionPosition currentPos_) { if (highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } + QueueIdleWork(WorkNeeded::workUpdateUI); } void Editor::SetEmptySelection(int currentPos_) { @@ -4641,18 +4644,13 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { } } - //Platform::DebugPrintf("** %x Doc Changed\n", this); - // TODO: could invalidate from mh.startModification to end of screen - //InvalidateRange(mh.position, mh.position + mh.length); if (paintState == notPainting && !CanDeferToLastStep(mh)) { - QueueStyling(pdoc->Length()); + QueueIdleWork(WorkNeeded::workStyle, pdoc->Length()); Redraw(); } } else { - //Platform::DebugPrintf("** %x Line Changed %d .. %d\n", this, - // mh.position, mh.position + mh.length); if (paintState == notPainting && mh.length && !CanEliminate(mh)) { - QueueStyling(mh.position + mh.length); + QueueIdleWork(WorkNeeded::workStyle, mh.position + mh.length); InvalidateRange(mh.position, mh.position + mh.length); } } @@ -6719,14 +6717,15 @@ void Editor::StyleToPositionInView(Position pos) { void Editor::IdleStyling() { // Style the line after the modification as this allows modifications that change just the // line of the modification to heal instead of propagating to the rest of the window. - StyleToPositionInView(pdoc->LineStart(pdoc->LineFromPosition(styleNeeded.upTo) + 2)); + if (workNeeded.items & WorkNeeded::workStyle) + StyleToPositionInView(pdoc->LineStart(pdoc->LineFromPosition(workNeeded.upTo) + 2)); NotifyUpdateUI(); - styleNeeded.Reset(); + workNeeded.Reset(); } -void Editor::QueueStyling(int upTo) { - styleNeeded.NeedUpTo(upTo); +void Editor::QueueIdleWork(WorkNeeded::workItems items, int upTo) { + workNeeded.Need(items, upTo); } bool Editor::PaintContains(PRectangle rc) { diff --git a/src/Editor.h b/src/Editor.h index 553cbeec0..bc7babb13 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -47,21 +47,30 @@ public: /** * When platform has a way to generate an event before painting, - * accumulate needed styling range in StyleNeeded to avoid unnecessary work. + * accumulate needed styling range and other work items in + * WorkNeeded to avoid unnecessary work inside paint handler */ -class StyleNeeded { +class WorkNeeded { public: + enum workItems { + workNone=0, + workStyle=1, + workUpdateUI=2 + }; bool active; + enum workItems items; Position upTo; - StyleNeeded() : active(false), upTo(0) {} + WorkNeeded() : active(false), items(workNone), upTo(0) {} void Reset() { active = false; + items = workNone; upTo = 0; } - void NeedUpTo(Position pos) { - if (upTo < pos) + void Need(workItems items_, Position pos) { + if ((items_ & workStyle) && (upTo < pos)) upTo = pos; + items = static_cast<workItems>(items | items_); } }; @@ -241,7 +250,7 @@ protected: // ScintillaBase subclass needs access to much of Editor PRectangle rcPaint; bool paintingAllText; bool willRedrawAll; - StyleNeeded styleNeeded; + WorkNeeded workNeeded; int modEventMask; @@ -532,7 +541,7 @@ protected: // ScintillaBase subclass needs access to much of Editor int PositionAfterArea(PRectangle rcArea); void StyleToPositionInView(Position pos); void IdleStyling(); - virtual void QueueStyling(int upTo); + virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo=0); virtual bool PaintContains(PRectangle rc); bool PaintContainsMargin(); |