sw/source/core/crsr/swcrsr.cxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
New commits: commit 41916d9fb045654fa19b4eac90a3099550a890f7 Author: László Németh <[email protected]> AuthorDate: Fri Jun 14 23:21:00 2024 +0200 Commit: László Németh <[email protected]> CommitDate: Sat Jun 15 02:13:36 2024 +0200 tdf#161563 sw: show "No Break" context menu only on a whole word It's possible to set CharNoHyphenation on shorter character sequences, than a word, but the result is not correct (use soft hyphens for alternative hyphenation within words), so limit "No Break" menu item only for selected words. (Not completely, because only Point() is checked for word boundary yet, not also Mark().) If no selection, cursor position must be within the hyphenated word (where "No Break" applied for the whole word automatically). This fixes also the assert in SwTextFrame::IsInHyphenatedWord(), when multiple nodes were selected. Follow-up to commit 2f0c7d5691acd4010443856788a54b0abc03098b "tdf#161563 tdf#161565 sw: add No Break to word context menu & visualize". Change-Id: I41b64e6a2eb0daf08f488420fc1eaba2045a28db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168898 Reviewed-by: László Németh <[email protected]> Tested-by: Jenkins diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index 3a986d37ddc0..2405aaf63eff 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -2370,6 +2370,19 @@ void SwCursor::RestoreSavePos() bool SwCursor::IsInHyphenatedWord(SwRootFrame const& rLayout) const { + // skip, if the selected text contains multiple nodes, long text or space, + // or not in word starting or word ending positions + if ( HasMark() && ( GetPoint()->GetNode() != GetMark()->GetNode() || + abs(GetPoint()->GetContentIndex() - GetMark()->GetContentIndex()) > 100 || + GetText().indexOf(' ') > -1 || + !( IsStartWordWT(css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, &rLayout) || + IsEndWordWT(css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, &rLayout) ) ) ) + return false; + + // skip, if no selection and the cursor is not in a word + if ( !HasMark() && !IsInWordWT(css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, &rLayout) ) + return false; + bool bRet = false; Point aPt; std::pair<Point, bool> const tmp(aPt, true); @@ -2377,7 +2390,7 @@ bool SwCursor::IsInHyphenatedWord(SwRootFrame const& rLayout) const &rLayout, GetPoint(), &tmp); if( pFrame && pFrame->IsTextFrame() ) { - SwPaM aPam( *GetPoint(), *GetMark() ); + SwPaM aPam( *GetPoint() ); bRet = static_cast<SwTextFrame const*>(pFrame)->IsInHyphenatedWord( &aPam, HasMark() ); } return bRet;
