sw/source/uibase/docvw/edtwin.cxx | 31 ++++++++++++++++++------------- sw/source/uibase/inc/edtwin.hxx | 1 - sw/source/uibase/uiview/view1.cxx | 3 +-- 3 files changed, 19 insertions(+), 16 deletions(-)
New commits: commit 455a69825ab6cfd9595c4c763181cc797c859816 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Feb 17 16:50:22 2022 +0100 Commit: Adolfo Jayme Barrientos <fit...@ubuntu.com> CommitDate: Mon Feb 21 13:05:57 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130123 Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com> diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 0fc6e91b594d..d6b30438853a 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -29,6 +29,8 @@ #include <com/sun/star/i18n/UnicodeScript.hpp> #include <com/sun/star/ui/ContextMenuExecuteEvent.hpp> +#include <comphelper/scopeguard.hxx> + #include <vcl/inputctx.hxx> #include <vcl/help.hxx> #include <vcl/weld.hxx> @@ -163,7 +165,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; @@ -872,6 +873,9 @@ static sal_uInt16 lcl_isNonDefaultLanguage(LanguageType eBufferLanguage, SwView */ void SwEditWin::FlushInBuffer() { + if ( m_aKeyInputFlushTimer.IsActive()) + m_aKeyInputFlushTimer.Stop(); + if ( m_aInBuffer.isEmpty() ) return; @@ -1000,8 +1004,6 @@ void SwEditWin::FlushInBuffer() rSh.Insert( m_aInBuffer ); m_eBufferLanguage = LANGUAGE_DONTKNOW; m_aInBuffer.clear(); - g_bFlushCharBuffer = false; - } #define MOVE_LEFT_SMALL 0 @@ -1391,7 +1393,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(); @@ -2469,10 +2473,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; } @@ -2688,11 +2697,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) @@ -5173,7 +5178,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 44985f903c86..96c7e3d45323 100644 --- a/sw/source/uibase/inc/edtwin.hxx +++ b/sw/source/uibase/inc/edtwin.hxx @@ -300,7 +300,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 ) {