From 2d1a8f83ce4c74b2ede1e93e8e1d309a61b8af23 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 22 Oct 2020 14:20:17 +0100 Subject: fix welded editengine delete-surrounding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I71c2f8e2483c2ef8d7f5cfcfcd7849f64792022f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104659 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- include/vcl/customweld.hxx | 1 + vcl/source/app/customweld.cxx | 7 +++++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 25 +++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/vcl/customweld.hxx b/include/vcl/customweld.hxx index b8c5490d0a15..64f980732dfb 100644 --- a/include/vcl/customweld.hxx +++ b/include/vcl/customweld.hxx @@ -152,6 +152,7 @@ private: DECL_LINK(DoStyleUpdated, weld::Widget&, void); DECL_LINK(DoRequestHelp, tools::Rectangle&, OUString); DECL_LINK(DoGetSurrounding, OUString&, int); + DECL_LINK(DoDeleteSurrounding, const Selection&, bool); public: CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId, diff --git a/vcl/source/app/customweld.cxx b/vcl/source/app/customweld.cxx index 9a56aeb0acbd..14fbef077454 100644 --- a/vcl/source/app/customweld.cxx +++ b/vcl/source/app/customweld.cxx @@ -39,6 +39,8 @@ CustomWeld::CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId, m_xDrawingArea->connect_command(LINK(this, CustomWeld, DoCommand)); m_xDrawingArea->connect_query_tooltip(LINK(this, CustomWeld, DoRequestHelp)); m_xDrawingArea->connect_im_context_get_surrounding(LINK(this, CustomWeld, DoGetSurrounding)); + m_xDrawingArea->connect_im_context_delete_surrounding( + LINK(this, CustomWeld, DoDeleteSurrounding)); } IMPL_LINK(CustomWeld, DoResize, const Size&, rSize, void) @@ -100,6 +102,11 @@ IMPL_LINK(CustomWeld, DoGetSurrounding, OUString&, rSurrounding, int) { return m_rWidgetController.GetSurroundingText(rSurrounding); } + +IMPL_LINK(CustomWeld, DoDeleteSurrounding, const Selection&, rSelection, bool) +{ + return m_rWidgetController.DeleteSurroundingText(rSelection); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 13f97ceb7df9..fd4c339f5337 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -13851,19 +13851,40 @@ public: if (nOffset > 0) { - while (nCursorIndex < sSurroundingText.getLength()) + while (nOffset && nCursorIndex < sSurroundingText.getLength()) + { sSurroundingText.iterateCodePoints(&nCursorIndex, 1); + --nOffset; + } } else if (nOffset < 0) { - while (nCursorIndex > 0) + while (nOffset && nCursorIndex > 0) + { sSurroundingText.iterateCodePoints(&nCursorIndex, -1); + ++nOffset; + } + } + + if (nOffset) + { + SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to move to offset: " << nOffset); + return false; } sal_Int32 nCursorEndIndex(nCursorIndex); sal_Int32 nCount(0); while (nCount < nChars && nCursorEndIndex < sSurroundingText.getLength()) + { + sSurroundingText.iterateCodePoints(&nCursorEndIndex, 1); ++nCount; + } + + if (nCount != nChars) + { + SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to select: " << nChars << " characters"); + return false; + } bRet = pThis->m_pArea->im_context_delete_surrounding(Selection(nCursorIndex, nCursorEndIndex)); } -- cgit