Issue with focusSelectFromStart - Does not Work as Described

edit: it appears focusSelect=“start” is not implemented, only focusSelectFromStart/focusSelectFromEnd?

i’d like to use focusSelect=“start” with the normal tiddler (body) editing

this would be really useful for new and current users, to avoid wiping tiddler contents by accident cf Focus on the body when entered into edit? - #6 by jonnie45

how can i choose/implement this? i found the documentation for
focusSelectFromStart at https://tiddlywiki.com/#EditTextWidget but not for focusSelect

i attempted to modify
$:/core/ui/EditTemplate/body/editor
(using an external editor)
to add
focusSelect=“start”
(or rather)
focusSelect=\\\"start\\\"\\n

but it didn’t appear to work

Use focusSelectFromStart="0"

thanks saq,

i tried focusSelectFromStart="0" initially but it selects all from the start, rather than leaving the cursor at the start but not selecting any text

focusSelectFromEnd=\\\"0\\\"\\n focusSelectFromStart=\\\"23235\\\"\\n

works to get the cursor at the end with no text selected because of the arbitrarily large number,
but the reverse

focusSelectFromEnd=\\\"23235\\\"\\n focusSelectFromStart=\\\"0\\\"\\n

does not result in the cursor at the beginning with no text selected

I don’t have the opportunity to investigate at present, but it is possible that the implementation that got merged does not match what was discussed.

A missing focusSelectFromEnd defaults to 0, i.e. the end of the text, rather than defaulting to the same position as the focusSelectFromStart attribute. As such I cannot see a means to create a zero length selection at the beginning or end of the text.

1 Like

i think the issue is in Add focusSelect attribute to <$edit-text> widget by Jermolene · Pull Request #7222 · Jermolene/TiddlyWiki5 · GitHub

line 46 of core/modules/utils/dom/dom.js

where
$tw.utils.setSelectionRangeSafe(node,selectFromStart,node.value.length - selectFromEnd);

probably cannot accept a negative number?

thus a large value for selectFromStart is ok, and if arbitrarily large enough, will result in a cursor at the end of the tiddler text with no selection

but a large value for selectFromEnd is not ok, as the result is a negative number? thus in the current implementation there is no way to specify a cursor at the beginning of the tiddler text with no selection (without using a known value (already stored somewhere?) for the length of the existing text; such that subtracting it makes the result 0, non-negative, or otherwise acceptable)

The docs tiddler is EditTextWidget

Did you have a closer look there?

1 Like

thanks pmario

i did try but as far as i can tell the current implementation does not work as intended for the scenario the OP and i ask about

try editing https://tiddlywiki.com/#EditTextWidget and substituting the values above; they don’t work as expected to give no selection and a cursor at the beginning of the text

Have you tried to calculate the correct zero-position instead of using an arbitrary large number?
In the docs example tiddler this works:

<$edit-text tiddler=<<currentTiddler>> field="caption" focus="yes" focusSelectFromEnd={{{ [{!!caption}length[]] }}} />

You don’t need to set focusSelectFromStart since that defaults to 0. This should work whether a fix is upcoming or not.

1 Like

thanks yaisog, thank you all!

that’s perfect! i modified

$:/core/ui/EditTemplate/body/editor
(using an external text editor)
to add
focusSelectFromEnd={{{ [<currentTiddler>get[text]length[]] }}}\\n
before
cancelPopups=“yes”

making sure (in control panel) to select default focus for new tiddlers to “text”

usability improvement for new users, being able to select this option in core (or have it be default) would be very helpful
to stop accidental erasure of tiddler contents (since the default for text selects the entire text field, any input will swiftly overwrite the contents)

i.e. a GUI dropdown to select “focus and cursor at start, nothing selected” i.e. focusSelectFromEnd to equal {{{ [get[text]length[]] }}}