summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-02-17 16:50:22 +0100
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2022-02-23 12:57:17 +0100
commita2da9348e705181abba0068081b014d398f2bf3d (patch)
treeee7781778c5b9d21b51a756edb8b4f8e3c40b26d
parenttdf#143817 Fix HUD deleting text contents in Writer (diff)
downloadcore-a2da9348e705181abba0068081b014d398f2bf3d.tar.gz
core-a2da9348e705181abba0068081b014d398f2bf3d.zip
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.lunak@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130093 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com> Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> Tested-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r--sw/source/uibase/docvw/edtwin.cxx31
-rw-r--r--sw/source/uibase/inc/edtwin.hxx1
-rw-r--r--sw/source/uibase/uiview/view1.cxx3
3 files changed, 19 insertions, 16 deletions
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index e4791daff6a0..59af6a581a6b 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;
@@ -871,6 +872,9 @@ static sal_uInt16 lcl_isNonDefaultLanguage(LanguageType eBufferLanguage, SwView
*/
void SwEditWin::FlushInBuffer()
{
+ if ( m_aKeyInputFlushTimer.IsActive())
+ m_aKeyInputFlushTimer.Stop();
+
if ( m_aInBuffer.isEmpty() )
return;
@@ -999,8 +1003,6 @@ void SwEditWin::FlushInBuffer()
rSh.Insert( m_aInBuffer );
m_eBufferLanguage = LANGUAGE_DONTKNOW;
m_aInBuffer.clear();
- g_bFlushCharBuffer = false;
-
}
#define MOVE_LEFT_SMALL 0
@@ -1389,7 +1391,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();
@@ -2455,10 +2459,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;
}
@@ -2674,11 +2683,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)
@@ -5187,7 +5192,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 a88e75c7bdec..5ec1942a17fd 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 )
{