aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-06-09 02:23:10 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-06-09 02:37:33 -0600
commit166ef3c94a46ed46ff0dd9a0eca0ce558449cfaf (patch)
tree056c36cdb662746f28076e36097d95b5c7dc397f
parentglobal: go fmt (diff)
downloadwireguard-windows-166ef3c94a46ed46ff0dd9a0eca0ce558449cfaf.tar.xz
wireguard-windows-166ef3c94a46ed46ff0dd9a0eca0ce558449cfaf.zip
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 <simon@rozman.si> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--ui/syntax/syntaxedit.c14
1 files 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';