diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-10-24 21:12:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-10-25 22:01:58 +0100 |
commit | 41df2d06cc13a1c60a4ea9671535afb8bd55b344 (patch) | |
tree | 96c61b2bed2a746657f1212b9cf53916e01b8bf7 /vcl/unx/gtk3/gtk3gtkframe.cxx | |
parent | 8d3a60ce43a36a4568c772afdb331f29e51503c2 (diff) |
Related: tdf#137620 factor out working IMDeleteSurrounding hunk
Change-Id: I7504e8670fb464fe3e76a3d38f1cac39ba2e9208
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104779
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx/gtk3/gtk3gtkframe.cxx')
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkframe.cxx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx index eb964a790533..7da09d72d375 100644 --- a/vcl/unx/gtk3/gtk3gtkframe.cxx +++ b/vcl/unx/gtk3/gtk3gtkframe.cxx @@ -4400,6 +4400,56 @@ gboolean GtkSalFrame::IMHandler::signalIMRetrieveSurrounding( GtkIMContext* pCon return false; } +Selection GtkSalFrame::CalcDeleteSurroundingSelection(const OUString& rSurroundingText, int nCursorIndex, int nOffset, int nChars) +{ + Selection aInvalid(-1, -1); + + if (nCursorIndex == -1) + return aInvalid; + + // Note that offset and n_chars are in characters not in bytes + // which differs from the usage other places in GtkIMContext + + if (nOffset > 0) + { + while (nOffset && nCursorIndex < rSurroundingText.getLength()) + { + rSurroundingText.iterateCodePoints(&nCursorIndex, 1); + --nOffset; + } + } + else if (nOffset < 0) + { + while (nOffset && nCursorIndex > 0) + { + rSurroundingText.iterateCodePoints(&nCursorIndex, -1); + ++nOffset; + } + } + + if (nOffset) + { + SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to move to offset: " << nOffset); + return aInvalid; + } + + sal_Int32 nCursorEndIndex(nCursorIndex); + sal_Int32 nCount(0); + while (nCount < nChars && nCursorEndIndex < rSurroundingText.getLength()) + { + rSurroundingText.iterateCodePoints(&nCursorEndIndex, 1); + ++nCount; + } + + if (nCount != nChars) + { + SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to select: " << nChars << " characters"); + return aInvalid; + } + + return Selection(nCursorIndex, nCursorEndIndex); +} + gboolean GtkSalFrame::IMHandler::signalIMDeleteSurrounding( GtkIMContext*, gint offset, gint nchars, gpointer /*im_handler*/ ) { |