|
1 | 1 | // This file is part of BowPad. |
2 | 2 | // |
3 | | -// Copyright (C) 2013-2024 - Stefan Kueng |
| 3 | +// Copyright (C) 2013-2025 - Stefan Kueng |
4 | 4 | // |
5 | 5 | // This program is free software: you can redistribute it and/or modify |
6 | 6 | // 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*/) |
230 | 230 | , m_autoCompleter(this, &m_editor) |
231 | 231 | , m_dwellStartPos(-1) |
232 | 232 | , m_bBlockAutoIndent(false) |
233 | | - , m_lastCheckedLine(0) |
| 233 | + , m_annotationsLastEndLine(0) |
| 234 | + , m_annotationsLastStartLine(0) |
234 | 235 | , m_hShieldIcon(nullptr) |
235 | 236 | , m_hCapsLockIcon(nullptr) |
236 | 237 | , m_hLexerIcon(nullptr) |
@@ -818,8 +819,16 @@ LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, |
818 | 819 | eolBytes = 1; |
819 | 820 | break; |
820 | 821 | } |
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) |
823 | 832 | { |
824 | 833 | auto curLineSize = m_editor.Scintilla().GetLine(line, nullptr); |
825 | 834 | if (curLineSize <= eolBytes) |
@@ -847,8 +856,8 @@ LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, |
847 | 856 | if (!textSet) |
848 | 857 | m_editor.Scintilla().EOLAnnotationSetText(line, nullptr); |
849 | 858 | } |
850 | | - if (m_lastCheckedLine < endLine) |
851 | | - m_lastCheckedLine = endLine; |
| 859 | + m_annotationsLastStartLine = startLine; |
| 860 | + m_annotationsLastEndLine = endLine; |
852 | 861 | } |
853 | 862 | } |
854 | 863 | break; |
@@ -1230,8 +1239,7 @@ LRESULT CMainWindow::HandleEditorEvents(const NMHDR& nmHdr, WPARAM wParam, LPARA |
1230 | 1239 | { |
1231 | 1240 | if (pScn->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) |
1232 | 1241 | { |
1233 | | - m_lastCheckedLine = m_editor.Scintilla().LineFromPosition(pScn->position); |
1234 | | - SetTimer(*this, TIMER_CHECKLINES, 300, nullptr); |
| 1242 | + RefreshAnnotations(); |
1235 | 1243 | } |
1236 | 1244 | } |
1237 | 1245 | break; |
@@ -5134,6 +5142,7 @@ void CMainWindow::SetTheme(bool dark) |
5134 | 5142 |
|
5135 | 5143 | void CMainWindow::RefreshAnnotations() |
5136 | 5144 | { |
5137 | | - m_lastCheckedLine = 0; |
| 5145 | + m_annotationsLastEndLine = 0; |
| 5146 | + m_editor.Scintilla().AnnotationClearAll(); |
5138 | 5147 | SetTimer(*this, TIMER_CHECKLINES, 300, nullptr); |
5139 | 5148 | } |
0 commit comments