include/vcl/textview.hxx     |    1 +
 vcl/source/edit/textview.cxx |   17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

New commits:
commit 809236ed826b67328409e008313dea87de6d5243
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Wed Dec 8 16:09:23 2021 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Sat Dec 11 16:57:57 2021 +0100

    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.heini...@yahoo.de>

diff --git a/include/vcl/textview.hxx b/include/vcl/textview.hxx
index 0983fa8eb660..29bc302d4d43 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 3c94e6fa6e1e..b295b78af8b0 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 );

Reply via email to