sw/source/uibase/docvw/edtwin.cxx | 30 +++++++++++++++++------------- sw/source/uibase/inc/edtwin.hxx | 1 - sw/source/uibase/uiview/view1.cxx | 3 +-- 3 files changed, 18 insertions(+), 16 deletions(-)
New commits: commit 17b39d150fce188f653632a3467891157375a1c6 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Feb 17 16:50:22 2022 +0100 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Fri Feb 18 07:49:45 2022 +0100 fix Writer key event delayed compression (tdf#145963) SwEditWin::KeyInput() was stopping the flush timer on every invocation, which means that as long as key events kept coming the timer would be started again and again and would not time out, and so the input buffer would not be actually processed. It seems that AnyInput(KEYBOARD) there actually does not normally manage to return true ... except for Win11 where it seems that now GetQueueStatus() detects even key-up events even though it didn't before (I've not debugged this enough to be certain). I think it still makes sense to have the compression in case Writer get overloaded to help it process the pending input events, so fix this (but if there are problems, I think an easy solution is simply to drop it, it doesn't seem to be that necessary). Also decrease the timeout from 200 to 20ms, as 200ms is a very visible delay. Change-Id: I760ad9c4f58726a80bd6a9fbf93f2771f10cbdb9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130083 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 6a0c5ac106b2..84c99e8049c0 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp> #include <com/sun/star/ui/ContextMenuExecuteEvent.hpp> +#include <comphelper/scopeguard.hxx> #include <comphelper/string.hxx> #include <vcl/dialoghelper.hxx> @@ -169,7 +170,6 @@ bool g_bFrameDrag = false; static bool g_bValidCursorPos = false; static bool g_bModePushed = false; bool g_bDDTimerStarted = false; -bool g_bFlushCharBuffer = false; bool g_bDDINetAttr = false; static SdrHdlKind g_eSdrMoveHdl = SdrHdlKind::User; @@ -877,6 +877,9 @@ static sal_uInt16 lcl_isNonDefaultLanguage(LanguageType eBufferLanguage, SwView */ void SwEditWin::FlushInBuffer() { + if ( m_aKeyInputFlushTimer.IsActive()) + m_aKeyInputFlushTimer.Stop(); + if ( m_aInBuffer.isEmpty() ) return; @@ -1005,8 +1008,6 @@ void SwEditWin::FlushInBuffer() rSh.Insert( m_aInBuffer ); m_eBufferLanguage = LANGUAGE_DONTKNOW; m_aInBuffer.clear(); - g_bFlushCharBuffer = false; - } #define MOVE_LEFT_SMALL 0 @@ -1395,7 +1396,9 @@ void SwEditWin::KeyInput(const KeyEvent &rKEvt) return; m_pShadCursor.reset(); - m_aKeyInputFlushTimer.Stop(); + // Do not reset the timer here, otherwise when flooded with events it would never time out + // if every key event stopped and started it again. + comphelper::ScopeGuard keyInputFlushTimerStop([this]() { m_aKeyInputFlushTimer.Stop(); }); bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly() && rSh.IsCursorReadonly(); @@ -2461,10 +2464,15 @@ KEYINPUT_CHECKTABLE_INSDEL: comphelper::string::padToLength(aBuf, m_aInBuffer.getLength() + aKeyEvent.GetRepeat() + 1, aCh); m_aInBuffer = aBuf.makeStringAndClear(); - g_bFlushCharBuffer = Application::AnyInput( VclInputFlags::KEYBOARD ); - bFlushBuffer = !g_bFlushCharBuffer; - if( g_bFlushCharBuffer ) - m_aKeyInputFlushTimer.Start(); + bool delayFlush = Application::AnyInput( VclInputFlags::KEYBOARD ); + bFlushBuffer = !delayFlush; + if( delayFlush ) + { + // Start the timer, make sure to not restart it. + keyInputFlushTimerStop.dismiss(); + if( !m_aKeyInputFlushTimer.IsActive()) + m_aKeyInputFlushTimer.Start(); + } } eKeyState = SwKeyState::End; } @@ -2680,11 +2688,7 @@ KEYINPUT_CHECKTABLE_INSDEL: // in case the buffered characters are inserted if( bFlushBuffer && !m_aInBuffer.isEmpty() ) { - // bFlushCharBuffer was not reset here - // why not? - bool bSave = g_bFlushCharBuffer; FlushInBuffer(); - g_bFlushCharBuffer = bSave; // maybe show Tip-Help if (bNormalChar) @@ -5193,7 +5197,7 @@ SwEditWin::SwEditWin(vcl::Window *pParent, SwView &rMyView): SetPointer( PointerStyle::Text ); m_aTimer.SetInvokeHandler(LINK(this, SwEditWin, TimerHandler)); - m_aKeyInputFlushTimer.SetTimeout( 200 ); + m_aKeyInputFlushTimer.SetTimeout( 20 ); m_aKeyInputFlushTimer.SetInvokeHandler(LINK(this, SwEditWin, KeyInputFlushHandler)); // TemplatePointer for colors should be reset without diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx index 108dbfb05307..9fb3da476f9b 100644 --- a/sw/source/uibase/inc/edtwin.hxx +++ b/sw/source/uibase/inc/edtwin.hxx @@ -301,7 +301,6 @@ public: extern bool g_bFrameDrag; extern bool g_bDDTimerStarted; -extern bool g_bFlushCharBuffer; extern bool g_bDDINetAttr; #endif diff --git a/sw/source/uibase/uiview/view1.cxx b/sw/source/uibase/uiview/view1.cxx index 1484b30054fd..979f5e0f5751 100644 --- a/sw/source/uibase/uiview/view1.cxx +++ b/sw/source/uibase/uiview/view1.cxx @@ -136,8 +136,7 @@ void SwView::Activate(bool bMDIActivate) void SwView::Deactivate(bool bMDIActivate) { - if( g_bFlushCharBuffer ) // Are Characters still in the input buffer? - GetEditWin().FlushInBuffer(); + GetEditWin().FlushInBuffer(); // Flush characters still in the input buffer. if( bMDIActivate ) {