diff options
author | Attila Szűcs <szucs.attila3@nisz.hu> | 2022-06-15 09:16:32 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2022-06-24 14:14:58 +0200 |
commit | 7ef9c3ef30023cc40068e1f735aa4bec4811288b (patch) | |
tree | 7ca6ee81f717a269e40f8699d3fb95985b3b4e9f /sw/qa | |
parent | b1c6b936a74e41655e6ba6680654d21d019e5256 (diff) |
Allow cursor movement on spaces over margin (or clicking it
it to position the cursor), like MSO does instead of stopping
cursor before the stripped (from the typesetting) spaces.
This way it's possible to follow the modification of these
characters, e.g. removing spaces or inserting other characters
at the cursor position.
Follow-up to commit 8741fd0e0ae9e346de2e09887f0668b831c9b48b
"tdf#43244 sw: show stripped line-end spaces on margin".
Details: extend SwHolePortion to calculate its width,
that can be used for cursor movement, even over the right
margin. Removed some code that not allowed cursor to be
positioned over the right margin. Layout calculation uses
m_nWidth variable (that was 0) to make frames. To keep the
layout unchanged, this new width calculated into m_nExtraBlankWidth temporarily, and this extra width is added to m_nWidth only
after the layout calculation is finished. (Ideally this 2 width
values could be stored and used separately, but that would require
a bigger refactor of the cursor calculation.)
Known regression: lost selection at Search & Replace, e.g. searching
double spaces: there was a narrow selection at end of the line
showing the position.
Other issues: when a different character inserted on the margin
resulting new line break, space formatting marks aren't updated
according to the less spaces. Removing the inserted character by
Backspace results losing of the cursor movement on the spaces.
Co-authored-by: Tibor Nagy (NISZ)
Change-Id: I94b4ed40b8c560e1ef32f4d0d3537e070c08666f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135895
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/text/data/tdf43100_tdf120715_cursorOnSpacesOverMargin.docx | bin | 0 -> 9606 bytes | |||
-rw-r--r-- | sw/qa/core/text/text.cxx | 68 |
2 files changed, 68 insertions, 0 deletions
diff --git a/sw/qa/core/text/data/tdf43100_tdf120715_cursorOnSpacesOverMargin.docx b/sw/qa/core/text/data/tdf43100_tdf120715_cursorOnSpacesOverMargin.docx Binary files differnew file mode 100644 index 000000000000..474d805d893e --- /dev/null +++ b/sw/qa/core/text/data/tdf43100_tdf120715_cursorOnSpacesOverMargin.docx diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 2db4d6dab348..99d80f649fef 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -470,6 +470,74 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRedlineDelete) pDoc->getIDocumentRedlineAccess().GetRedlineTable().size()); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf120715_CursorMoveWhenTypingSpaceAtCenteredLineEnd) +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf43100_tdf120715_cursorOnSpacesOverMargin.docx"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // Make a paint to force the call of AddExtraBlankWidth, that calculate width for holePortions. + pDoc->GetDocShell()->GetPreviewBitmap(); + + // Move the cursor to the last character of the document. + pWrtShell->EndOfSection(); + + //Press space and check if the cursor move right with the additional space. + sal_Int32 nOldCursorPos = pWrtShell->GetCharRect().Left(); + pWrtShell->Insert(" "); + sal_Int32 nNewCursorPos = pWrtShell->GetCharRect().Left(); + CPPUNIT_ASSERT_GREATER(nOldCursorPos, nNewCursorPos); +} + +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf43100_CursorMoveToSpacesOverMargin) +{ + // Test the cursor movement over the right margin in several different paragraphs. + // These differences are based on its paragraphs + // - alignment (left, center, right, justified), + // - line count (1 line, 2 lines, blank line containing only spaces) + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf43100_tdf120715_cursorOnSpacesOverMargin.docx"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // Make a paint to force the call of AddExtraBlankWidth, that calculate width for holePortions. + pDoc->GetDocShell()->GetPreviewBitmap(); + + // Move the cursor to the 2. line. + pWrtShell->Down(/*bSelect=*/false, 1, /*bBasicCall=*/false); + // Move the cursor to the right margin. + pWrtShell->RightMargin(false, false); + + sal_Int32 nMarginPos = pWrtShell->GetCharRect().Left(); + sal_Int32 nLastCursorPos = nMarginPos; + + // Move the cursor right 5 times, every step should increase the cursor x position. + // Before this fix, the cursor stopped at the margin. + for (int i = 0; i < 5; i++) + { + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + sal_Int32 nNewCursorPos = pWrtShell->GetCharRect().Left(); + CPPUNIT_ASSERT_GREATER(nLastCursorPos, nNewCursorPos); + nLastCursorPos = nNewCursorPos; + } + + // Move down the cursor several lines, and check if it will keep nearly its horizontal position. + // Some of the lines are not reach beyond the margin, there the cursor won't be able to keep its + // original position. + bool aLineReachOverMargin[] = { false, true, true, false, false, true, true, false, true, + true, true, true, false, true, true, false, false }; + // Cursor position can be a bit inaccurate, because it can only be positioned on characters, + // that is based on the actual line layout, therefore the actual cursor position + // is checked against a more distinct position instead of the nMarginPos. + sal_Int32 nAvgLeft = (nMarginPos + nLastCursorPos) / 2; + for (int i = 2; i < 17; i++) + { + pWrtShell->Down(/*bSelect=*/false, 1, /*bBasicCall=*/false); + sal_Int32 nNewCursorPos = pWrtShell->GetCharRect().Left(); + if (aLineReachOverMargin[i]) + CPPUNIT_ASSERT_GREATER(nAvgLeft, nNewCursorPos); + else + CPPUNIT_ASSERT_LESS(nAvgLeft, nNewCursorPos); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |