Skip to content

Commit 1c71cf5

Browse files
committed
improve performance of annotations
1 parent 0260159 commit 1c71cf5

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/MainWindow.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BowPad.
22
//
3-
// Copyright (C) 2013-2024 - Stefan Kueng
3+
// Copyright (C) 2013-2025 - Stefan Kueng
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -230,7 +230,8 @@ CMainWindow::CMainWindow(HINSTANCE hInst, const WNDCLASSEX* wcx /* = nullptr*/)
230230
, m_autoCompleter(this, &m_editor)
231231
, m_dwellStartPos(-1)
232232
, m_bBlockAutoIndent(false)
233-
, m_lastCheckedLine(0)
233+
, m_annotationsLastEndLine(0)
234+
, m_annotationsLastStartLine(0)
234235
, m_hShieldIcon(nullptr)
235236
, m_hCapsLockIcon(nullptr)
236237
, m_hLexerIcon(nullptr)
@@ -818,8 +819,16 @@ LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam,
818819
eolBytes = 1;
819820
break;
820821
}
821-
auto endLine = m_editor.Scintilla().DocLineFromVisible(m_editor.Scintilla().FirstVisibleLine()) + m_editor.Scintilla().LinesOnScreen();
822-
for (sptr_t line = m_lastCheckedLine; line <= endLine; ++line)
822+
auto firstVisibleDocLine = m_editor.Scintilla().DocLineFromVisible(m_editor.Scintilla().FirstVisibleLine());
823+
auto lastVisibleDocLine = m_editor.Scintilla().DocLineFromVisible(m_editor.Scintilla().FirstVisibleLine() + m_editor.Scintilla().LinesOnScreen());
824+
auto startLine = firstVisibleDocLine;
825+
auto endLine = lastVisibleDocLine;
826+
// adjust startLine and endLine to exclude the range m_annotationsLastStartLine to m_annotationsLastEndLine
827+
if (m_annotationsLastEndLine > startLine && m_annotationsLastEndLine < endLine)
828+
startLine = m_annotationsLastEndLine;
829+
if (m_annotationsLastStartLine > startLine && m_annotationsLastStartLine < endLine)
830+
endLine = m_annotationsLastStartLine;
831+
for (sptr_t line = startLine; line <= endLine; ++line)
823832
{
824833
auto curLineSize = m_editor.Scintilla().GetLine(line, nullptr);
825834
if (curLineSize <= eolBytes)
@@ -847,8 +856,8 @@ LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam,
847856
if (!textSet)
848857
m_editor.Scintilla().EOLAnnotationSetText(line, nullptr);
849858
}
850-
if (m_lastCheckedLine < endLine)
851-
m_lastCheckedLine = endLine;
859+
m_annotationsLastStartLine = startLine;
860+
m_annotationsLastEndLine = endLine;
852861
}
853862
}
854863
break;
@@ -1230,8 +1239,7 @@ LRESULT CMainWindow::HandleEditorEvents(const NMHDR& nmHdr, WPARAM wParam, LPARA
12301239
{
12311240
if (pScn->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
12321241
{
1233-
m_lastCheckedLine = m_editor.Scintilla().LineFromPosition(pScn->position);
1234-
SetTimer(*this, TIMER_CHECKLINES, 300, nullptr);
1242+
RefreshAnnotations();
12351243
}
12361244
}
12371245
break;
@@ -5134,6 +5142,7 @@ void CMainWindow::SetTheme(bool dark)
51345142

51355143
void CMainWindow::RefreshAnnotations()
51365144
{
5137-
m_lastCheckedLine = 0;
5145+
m_annotationsLastEndLine = 0;
5146+
m_editor.Scintilla().AnnotationClearAll();
51385147
SetTimer(*this, TIMER_CHECKLINES, 300, nullptr);
51395148
}

src/MainWindow.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BowPad.
22
//
3-
// Copyright (C) 2013-2018, 2020-2024 - Stefan Kueng
3+
// Copyright (C) 2013-2018, 2020-2025 - Stefan Kueng
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -251,7 +251,8 @@ class CMainWindow : public CWindow
251251
CAutoComplete m_autoCompleter;
252252
Sci_Position m_dwellStartPos;
253253
bool m_bBlockAutoIndent;
254-
sptr_t m_lastCheckedLine;
254+
sptr_t m_annotationsLastEndLine;
255+
sptr_t m_annotationsLastStartLine;
255256

256257
// status bar icons
257258
HICON m_hShieldIcon;

0 commit comments

Comments
 (0)