From 4d9d8d22e3666076988c30afb4e7c6fe365c19aa Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期二, 06 一月 2026 18:53:04 +0800
Subject: [PATCH] 1.修复一个回复错误的问题;
---
SourceCode/Bond/Servo/LogEdit.cpp | 64 ++++++++++++++++++++-----------
1 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/SourceCode/Bond/Servo/LogEdit.cpp b/SourceCode/Bond/Servo/LogEdit.cpp
index 3b4742f..6330dc4 100644
--- a/SourceCode/Bond/Servo/LogEdit.cpp
+++ b/SourceCode/Bond/Servo/LogEdit.cpp
@@ -21,12 +21,13 @@
BEGIN_MESSAGE_MAP(CLogEdit, CEdit)
ON_WM_CONTEXTMENU()
ON_WM_VSCROLL()
+ ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
void CLogEdit::SetMaxLineCount(int line)
{
m_nMaxLines = line;
- m_nTrimLines = min(m_nMaxLines, 100);
+ m_nTrimLines = min(m_nMaxLines, 4000);
}
void CLogEdit::OnContextMenu(CWnd* pWnd, CPoint point)
@@ -60,6 +61,13 @@
CEdit::OnVScroll(nSBCode, nPos, pScrollBar);
}
+BOOL CLogEdit::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
+{
+ // 每次滚动时检查是否还在底部
+ m_bAutoScroll = IsScrollBarAtBottom();
+ return CEdit::OnMouseWheel(nFlags, zDelta, pt);
+}
+
BOOL CLogEdit::IsScrollBarAtBottom()
{
SCROLLINFO si = { sizeof(si), SIF_ALL };
@@ -69,31 +77,41 @@
void CLogEdit::AppendText(const char* pszText)
{
- SetRedraw(FALSE);
+ SetRedraw(FALSE);
- // 裁剪逻辑
- int totalLines = GetLineCount();
- if (totalLines > m_nMaxLines) {
- // 获取要删除的字符范围
- int startChar = LineIndex(0); // 第0行首字符位置
- int endChar = LineIndex(m_nTrimLines); // 第N行首字符位置
+ // 剪切过多行
+ int totalLines = GetLineCount();
+ if (totalLines > m_nMaxLines) {
+ int startChar = LineIndex(0);
+ int endChar = LineIndex(m_nTrimLines);
+ if (startChar >= 0 && endChar > startChar) {
+ SetSel(startChar, endChar);
+ ReplaceSel(_T(""));
+ }
+ }
- if (startChar >= 0 && endChar > startChar) {
- SetSel(startChar, endChar);
- ReplaceSel(_T("")); // 删除前面行
- }
- }
+ // 保存当前选择
+ int start, end;
+ GetSel(start, end);
+ bool hasSelection = (start != end);
+ int endPos = GetWindowTextLength();
+ SetSel(endPos, endPos);
+ ReplaceSel(pszText);
- int len = GetWindowTextLength();
- SetSel(len, len);
- ReplaceSel(pszText);
+ if (m_bAutoScroll && !hasSelection) {
+ LineScroll(GetLineCount());
+ }
- if (m_bAutoScroll) {
- LineScroll(GetLineCount());
- }
+ // 恢复选择
+ if (hasSelection) {
+ SetSel(start, end);
+ }
- SetRedraw(TRUE);
- Invalidate();
- UpdateWindow();
-}
\ No newline at end of file
+ SetRedraw(TRUE);
+
+ if (m_bAutoScroll && !hasSelection) {
+ Invalidate();
+ UpdateWindow();
+ }
+}
--
Gitblit v1.9.3