tdf#145764 - BASIC IDE Home Key: move cursor to the beginning/first character

Pressing the Home Key moves the cursor to the first character in the
line, whereas pressing it at line start moves it to the first character
in that line.

Change-Id: I8eabb6d01b1a4de0d24bf064f82c83342ca91396
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126548
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
diff --git a/include/vcl/textview.hxx b/include/vcl/textview.hxx
index 0983fa8..29bc302 100644
--- a/include/vcl/textview.hxx
+++ b/include/vcl/textview.hxx
@@ -196,6 +196,7 @@ public:
    TextPaM             CursorDown( const TextPaM& rPaM );
    TextPaM             CursorLeft( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode );
    TextPaM             CursorRight( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode );
    TextPaM             CursorFirstWord( const TextPaM& rPaM );
    TextPaM             CursorWordLeft( const TextPaM& rPaM );
    TextPaM             CursorWordRight( const TextPaM& rPaM );
    TextPaM             CursorStartOfLine( const TextPaM& rPaM );
diff --git a/vcl/source/edit/textview.cxx b/vcl/source/edit/textview.cxx
index 3c94e6f..b295b78 100644
--- a/vcl/source/edit/textview.cxx
+++ b/vcl/source/edit/textview.cxx
@@ -1016,7 +1016,11 @@ TextSelection const & TextView::ImpMoveCursor( const KeyEvent& rKeyEvent )
                            break;
        case KEY_DOWN:      aPaM = CursorDown( aPaM );
                            break;
        case KEY_HOME:      aPaM = bCtrl ? CursorStartOfDoc() : CursorStartOfLine( aPaM );
        case KEY_HOME:
            // tdf#145764 - move cursor to the beginning or first character in the same line
            aPaM = bCtrl                  ? CursorStartOfDoc()
                   : aPaM.GetIndex() == 0 ? CursorFirstWord( aPaM )
                                          : CursorStartOfLine( aPaM );
                            break;
        case KEY_END:       aPaM = bCtrl ? CursorEndOfDoc() : CursorEndOfLine( aPaM );
                            break;
@@ -1156,6 +1160,17 @@ TextPaM TextView::CursorRight( const TextPaM& rPaM, sal_uInt16 nCharacterIterato
    return aPaM;
}

TextPaM TextView::CursorFirstWord( const TextPaM& rPaM )
{
    TextPaM aPaM(rPaM);
    TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[aPaM.GetPara()].get();

    css::uno::Reference<css::i18n::XBreakIterator> xBI = mpImpl->mpTextEngine->GetBreakIterator();
    aPaM.GetIndex() = xBI->nextWord(pNode->GetText(), 0, mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES).startPos;

    return aPaM;
}

TextPaM TextView::CursorWordLeft( const TextPaM& rPaM )
{
    TextPaM aPaM( rPaM );