Focus cursor at beginning of text field?

Hi all

I have a custom new here button in the view toolbar. The tiddlers created with this button have prepopulated titles, and text in the text fields.

I would like to add an action thingy to focus the cursor at the beginning of the text field, before any of the text there.

Any ideas?

2 Likes

If it helps, the first lines of the tiddlers created with this button are empty.

Bump! And add some random words to reach 20 characters.

See this recent thread it may contain the answer or a lead to finding a solution Focus on the body when entered into edit?

see [IDEA] it is proposed to add a "focusSelect" parameter to the edit-text widget ¡ Issue #7221 ¡ Jermolene/TiddlyWiki5 ¡ GitHub

1 Like

Should also be an option to have focus:none, that is, instead of focusing on a specific field, just have no focus.

1 Like

I have posted example code changes to implement this [IDEA], and Jeremy has added a PR (with somewhat different code, but achieving the same end goals). This will likely be committed for v5.2.6. See Add focusSelect attribute to <$edit-text> widget by Jermolene ¡ Pull Request #7222 ¡ Jermolene/TiddlyWiki5 ¡ GitHub for the pull request, and https://tiddlywiki5-git-edit-text-focus-select-attribute-jermolene.vercel.app/ for the pre-commitment build.

Usage:
When an $edit-text widget has focus="yes", you can use an additional parameter, focusSelect, to control how initial selection is applied:

  • focusSelect="yes" (default) - Selects the entire edit control contents
  • focusSelect="start" - No selection is made. The cursor is placed at the start of the edit control contents
  • focusSelect="no" - No selection is made. The cursor is placed at the end of the edit control contents
  • focusSelect="end" - No selection is made. The cursor is placed at the end of the edit control contents

Note that this new handling is only applied if the $edit-text widget is of type “text” (default), “search”, “URL”, “tel” or “password”. For any other specified type or any unrecognized value of focusSelect, the current behavior is applied (i.e., the entire edit control contents is selected if focus="yes" is used)

enjoy,
-e

3 Likes

This is separate from the focusSelect parameter handling, and can currently be achieved without any TWCore code changes by manually clearing the text field content in $:/config/AutoFocus (or setting the text to any non-existent field name, e.g., “none”).

2 Likes

You just made me a happy man! Thanks Eric! They should make ‘none’ one of the options in the dropdown in Control Panel > Basics

Try this:

Edit shadow tiddler $:/snippets/minifocusswitcher, and add this line:

<option value="">(none)</option>

immediately after this line

<$select tiddler="$:/config/AutoFocus">
2 Likes

This will be really good for use with custom “New Tiddler titles” creating a lot of tiddlers with the same prefix and you just type the “unique suffix”

2 Likes

I just went to make use of this and wonder if my use case is catered for or not?

  • After Projectify creates a todo item, I am using action create tiddler widget I use the following to open the tiddler for edit (a second add/edit button);
    <$action-sendmessage $message="tm-edit-tiddler" $param={{$:/temp/projectify/new-todo}}/>
  • In this case I would like the text field given the focus as the title is already determined, but I don’t want this for all edit tiddlers because I usually want to rename the tiddler, ie focus on title.

One would think WidgetMessage: tm-focus-selector may be the answer but the documentation is insufficient and no examples given.

7 posts were split to a new topic: Issue with focusSelectFromStart - Does not Work as Described