From 166ef3c94a46ed46ff0dd9a0eca0ce558449cfaf Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 9 Jun 2020 02:23:10 -0600 Subject: syntax: skip highlights if too many spans The rich text control is slow, so keep in plain text if there's too many. Suggested-by: Simon Rozman Signed-off-by: Jason A. Donenfeld --- ui/syntax/syntaxedit.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/syntax/syntaxedit.c b/ui/syntax/syntaxedit.c index 80cff689..c18d496b 100644 --- a/ui/syntax/syntaxedit.c +++ b/ui/syntax/syntaxedit.c @@ -143,6 +143,7 @@ static void highlight_text(HWND hWnd) POINT original_scroll; bool found_private_key = false; COLORREF bg_color, bg_inversion; + size_t num_spans; if (this->highlight_guard) return; @@ -181,12 +182,15 @@ static void highlight_text(HWND hWnd) bg_color = GetSysColor(COLOR_WINDOW); bg_inversion = (bg_color & RGB(0xFF, 0xFF, 0xFF)) ^ RGB(0xFF, 0xFF, 0xFF); SendMessage(hWnd, EM_SETBKGNDCOLOR, 0, bg_color); + num_spans = _msize(spans) / sizeof(spans[0]); for (struct highlight_span *span = spans; span->type != HighlightEnd; ++span) { - CHARRANGE selection = { span->start, span->len + span->start }; - SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM)&selection); - format.crTextColor = stylemap[span->type].color ^ bg_inversion; - format.dwEffects = stylemap[span->type].effects; - SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format); + if (num_spans <= 2048) { + CHARRANGE selection = { span->start, span->len + span->start }; + SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM)&selection); + format.crTextColor = stylemap[span->type].color ^ bg_inversion; + format.dwEffects = stylemap[span->type].effects; + SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format); + } if (span->type == HighlightPrivateKey && !found_private_key) { /* Rather than allocating a new string, we mangle this one, since (for now) we don't use msg again. */ msg[span->start + span->len] = '\0'; -- cgit v1.2.3-59-g8ed1b