From 809236ed826b67328409e008313dea87de6d5243 Mon Sep 17 00:00:00 2001 From: Andreas Heinisch Date: Wed, 8 Dec 2021 16:09:23 +0100 Subject: 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 --- vcl/source/edit/textview.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'vcl') 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 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 ); -- cgit