Bug 137494 - Cycle text selection per shortcut
Summary: Cycle text selection per shortcut
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: x86 (IA32) Windows (All)
: medium enhancement
Assignee: Dipanshu Garg
URL:
Whiteboard: target:7.2.0
Keywords: difficultyMedium, easyHack, skillCpp, topicUI
Depends on:
Blocks: Selection
  Show dependency treegraph
 
Reported: 2020-10-15 07:50 UTC by juergenkohler23
Modified: 2021-06-04 13:10 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description juergenkohler23 2020-10-15 07:50:12 UTC
Description:
Improvement suggestion:

In Microsoft Word it is possible to mark text by pressing "F8":

1. press: nothing happens
2. press: marks the first word behind the cursor
3. press: marks the whole sentence the cursor is currently located in
4. press: marks the whole paragraph the cursor is currently located in
5. press: marks the whole text

Steps to Reproduce:
1. open LibreOffice
2. Type/copy a text in a document
3. Press "F8":

1. press: nothing happens
2. press: marks the first word behind the cursor
3. press: marks the whole sentence the cursor is currently located in
4. press: marks the whole paragraph the cursor is currently located in
5. press: marks the whole text

Actual Results:
Nothing happens/is marked by pressing "F8" (several times)

Expected Results:
Marking of text by pressing "F8" multiple times


Reproducible: Always


User Profile Reset: No



Additional Info:
Windows
Edition	Windows 		10 Home
Version				1909
Installed on			17.02.2020
Operating system build		18363.1016

LibreOffice
Version: 	7.0.2.2 (x64)
Build ID: 	8349ace3c3162073abd90d81fd06dcfb6b36b994
CPU threads: 	4; OS: Windows 10.0 Build 18363; UI render: Skia/Vulkan; VCL: win
Locale: 		de-DE (de_DE); UI: de-DE
Calc: 		threaded
Comment 1 Peter Franke 2020-10-15 09:37:47 UTC
The function would be very useful for people who need to use a keyboard, such as blind and visually impaired people. It would be great if this idea could be implemented!
Comment 2 V Stuart Foote 2020-10-15 14:14:22 UTC
This cyclic selection sequence is already provided, but is lmouse click based: 2 - word, 3 - sentence, 4 - paragraph in the editshell, not UNO based.

There are direct UNO controls for selection that can be assigned Tools -> Customize dialog to keyboard shortcut, e.g. Select Word (uno:SelectWord), Select Sentence (uno:SelectSentence) , Select Paragraph (uno:SelectText). 

And I personally will assign a shortcut to Select Word for reduced mouse use.

So I guess similar to the current <Shift>+<F3> 'Cycle Case' transliterations, a selection could be made cyclically to match the lmouse click selection.

However LO already provides a very robust keyboard based block selection [1].
The <F8> is already assigned for Extended selection mode, <Shfit>+<F8> for Adding selection,, and <Ctrl><Shift>+<F8> for Block selection.

Selections are extended with cursor <L,R,U,D> with modification using <Ctrl> and <Shift>.

Current Selection-mode is available on the Status bar (which does require mouse action to expose the mode list and selection).

But sure, a simple cyclic selection behavior with the existing UNO--even overloading the <F8> might be workable.

+1  

=-ref-=
[1] https://help.libreoffice.org/7.1/en-US/text/shared/02/20050000.html?&DbPAR=WRITER
Comment 3 Heiko Tietze 2020-10-16 11:10:50 UTC
(In reply to V Stuart Foote from comment #2)
> But sure, a simple cyclic selection behavior with the existing UNO--even
> overloading the <F8> might be workable.

Do you have F8 in mind for toggling uno:SelectWord > SelectSentence > SelectText > SelectWord... (not sure it unselects the text) or to combine the current F8 shortcuts? Guess the first- reassign F8 in this case?
Comment 4 V Stuart Foote 2020-10-16 14:22:28 UTC
Sure, reuse the <F8>.

@Cor?
Comment 5 Thomas Lendo 2020-10-20 17:27:15 UTC
(In reply to Heiko Tietze from comment #3)
> (In reply to V Stuart Foote from comment #2)
> > But sure, a simple cyclic selection behavior with the existing UNO ...
> Do you have F8 in mind for toggling uno:SelectWord > SelectSentence >
> SelectText > SelectWord... (not sure it unselects the text) ...
Good idea. +1
The last step before new beginning of the cycle should be 'nothing selected'.
Comment 6 Heiko Tietze 2020-10-22 13:17:04 UTC
We discussed Stuart's proposal to toggle the selection in the design meeting and welcome the idea. Would be good to use F8 to comply with MSO (and change Extend Selection to use Alt+F8) but alternatively also vice versa.

Jim, could you please add some code pointers? Think it's a medium difficult easy hack.
Comment 7 Jim Raykowski 2020-10-24 08:11:20 UTC
I think this is a nice opportunity for some fun LO hacking indeed :-)

Here are some code pointers: 

A user command for this will be needed.
Perhaps .uno:CycleSelection or .uno:SelectionCycle? 
Feel free to chime in with a better command name.

An example how to add a Writer user interface command is here:
https://gerrit.libreoffice.org/c/core/+/91605

Details of how this works is here:
https://wiki.openoffice.org/wiki/Framework/Article/Implementation_of_the_Dispatch_API_In_SFX2

Look here to do the implemention of the command:
sw/source/uibase/uiview/view2.cxx
void SwView::ExecuteSfxRequest &rReq)

The original cursor position, point and mark positions of the selection cycle, and selection cycle step number will be useful to store. A struct with a member variable assigned in the SwView class might work well for this purpose.

Any selection(s) when the cycle is initiated should be cleared and word selection should be done from current cursor position.
If point and/or mark positions are changed before the next selection cycle step the cycle step should return to word selection.

The following functions will be of use to cycle selection thru word, sentence, and paragraph and to set the cursor to the original cursor position with no selection.

sw/inc/crsrsh.hxx
SwCursorShell::GetCursor_
SwCursorShell::SetCursor 

sw/inc/viscrs.hxx
SwShellCursor::GetPtPos
SwShellCursor::GetMkPos

sw/source/uibase/inc/wrtsh.hxx
SwWrtShell::IsSelection
SwWrtShell::MoveCursor
SwWrtShell::SelWrd
SwWrtShell::SelSentence
SwWrtShell::SelPara
Comment 8 Jim Raykowski 2020-10-25 06:45:09 UTC
(In reply to Jim Raykowski from comment #7)

> Any selection(s) when the cycle is initiated should be cleared and word
> selection should be done from current cursor position.

Maybe not clearing the current selections, like the ctrl+lmouse multiclicks behavior, is better. SwCursorShell::ClearMark should be useful for implementing this behavior and SwWrtShell::IsSelection and SwWrtShell::MoveCursor not needed.

FWIW: sw/soure/uibase/docvw/edtwin.cxx SwEditWin::MouseButtonDown is where the mouse multiclicks selection is implemented.
Comment 9 Dipanshu Garg 2021-03-08 10:38:28 UTC
Hi, I would like to work on this.
Comment 10 Dipanshu Garg 2021-03-10 12:30:20 UTC
Hi, I have added a command .uno:SelectionCycle and also implemented it in void SwView::ExecuteSfxRequest &rReq).

I have a question.
Currently I am able to see a command 'Cycle Select' in writer commands. But it is not assigned to any key. I am not sure where this assignment of key to command is coded. Can you please help me?
Comment 11 Heiko Tietze 2021-03-10 13:05:01 UTC
(In reply to Dipanshu Garg from comment #10)
> ... where this assignment of key to command is coded

UNO commands can be assigned to a hard-coded shortcut in officecfg/registry/data/org/openoffice/Office/Accelerators.xcu.
Comment 12 Commit Notification 2021-03-14 15:14:01 UTC
dipanshu124 committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d97528da0c70c43fccd3239cbe8e064c3480bba8

tdf#137494 Add Select Cycle uno command

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 BogdanB 2021-06-04 10:51:25 UTC
It's ok except that it is working like this:

1. press: nothing happens <--- OK
2. press: marks the first word behind the cursor <--- OK
3. press: marks the whole sentence the cursor is currently located in <--- OK
4. press: marks the whole paragraph the cursor is currently located in <--- OK
5. press: marks the whole text <------ this is NOT happening in 7.2.0

Tested in 
Version: 7.2.0.0.alpha1+ (x64) / LibreOffice Community
Build ID: 3b57ebb445df8a2bc3d916ea79f8af45e20e4e62
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: ro-RO (ro_RO); UI: en-US
Calc: threaded

Could someone test this?
Comment 14 V Stuart Foote 2021-06-04 12:12:03 UTC
(In reply to BogdanB from comment #13)
> It's ok except that it is working like this:
> ... 
> Could someone test this?

Yes and that is implemented as intended, and there is absolutely no requirement for a 5th <F8> to 'Select All'; the keyboard shortcut for that is the ubiquituous <Ctrl>+A.  MS has a much different 'Selection' model for <F8> which we do not follow. And after doing an 'all' selection its <F8> cycling does not get back to a 'none'. Clearing the selection reuiqres reversing backward with <Shitf>+<F8>, or moving the mouse cursor and making a different selection.

Our LO Implementation is cleaner and follows our mouse click cycling of word, sentence, paragrapha, none. And keeps document focus within the current paragraph--much simpler UI.

Version: 7.2.0.0.alpha1+ (x64) / LibreOffice Community
Build ID: 3b57ebb445df8a2bc3d916ea79f8af45e20e4e62
CPU threads: 8; OS: Windows 10.0 Build 19042; UI render: Skia/Vulkan; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
Comment 15 BogdanB 2021-06-04 13:10:58 UTC
Ok, then.
Thanks for fixing this bug. 

It's verified in
Version: 7.2.0.0.alpha1+ (x64) / LibreOffice Community
Build ID: 3b57ebb445df8a2bc3d916ea79f8af45e20e4e62
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: ro-RO (ro_RO); UI: en-US
Calc: threaded