How to disable the focus on the tiddler of the tiddler I'm editing

Ideally it would be handy if this option it was still active the first time I create a new tiddler. (i.e. when I click the “+” button)

But then when I’m editing a tiddler I find it awkward, especially because some actions force the activation of this focus, perhaps by scrolling a dozen tiddlers to go to the title of the one that I left in edit some time ago, and forcing me to scroll up to find where I was left.
An example of these actions is the a button that switches between a light and dark palette, or more generally when you switch palettes, but it happened also in other occasions that I couldn’t replicate now.
In general I find this option inconvenient. Is there a way to disable it?

-Sam

1 Like

Hi @SnapSam there’s currently no way to prevent the focus being given to newly created tiddlers, but there is a select box in control panel that allows the field that is focussed by default to be customised.

See control panel → Info → Basics and look for “Default focus field for new tiddlers”

1 Like

Hello, I feel really privileged to be able to write to you. Thank you for the reply, but perhaps I have explained myself badly.
The fact that a focus is given to the “title” field of a newly created tiddler is a desirable thing, the thing I would like to avoid is that when I’m editing a tiddler and I perform certain actions the focus moves to the title of the tiddler I’m editing.
I don’t know how to explain it exactly, but it’s easy to replicate it. You can quickly test it on https://tiddlywiki.com/: if you edit “GettingStarted” and scroll away from there and then change palette, the focus will be put on the title of “GettingStarted” in the editor. (This is the “focus” I would like to avoid)

-Sam

I reproduced this as you illustrated. I think it is jumping to the last edited tiddler and selecting the title, thus losing the position of the cursor.

  • My guess, with a little experimentation, is clicking the pallet selector changes the position of the cursor but jumps to the last tiddler in the story and selects the title.
  • When you select a new pallet $:/snippets/paletteswitcher then $:/core/ui/ControlPanel/Palette uses some reveal widgets to display the palet editor belowand that is affecting the focus.

[Edited] I notice a bug listed on the prerelease says;

fixed bug whereby scrolling occurs if the linkcatcher widget triggers an action-navigate and the $scroll attribute is set to “no”

  • I observed the linkcatcher widget is in use in the palet handling, however the “bug” you pointed out is still occurring in the pre-release.

Perhaps this is something for the devs and/or @jeremyruston

1 Like

That’s actually the exact same thing. So you can not have one without the other. The title-input has an attribute set to “autofocus”. So as soon as it is rendered, this input field will “catch” the focus.

Changing the palette activates a complete page re-render. So the last input-field that is rendered and has the “autofocus” field set, will get the focus.

So we probably could set ControlPanel → Info → Basics → Default focus field to “none”, but that would also disable the “autofocus” if you create a new tiddler.

2 Likes

Ah, now I understand the mechanism.
So if that’s the case, I’ll leave it as it is, I think I can adapt.
Thanks for the explanation!

P.S.
I put your answer as a solution not so much because the problem no longer exists, but because it is pertinent and explains the situation

I have followed your instructions and set Default focus field to “none”, but when I click New Tiddler Button, the focus still changes. How do I avoid that focus change completely (or at least put the New Tiddler Edit pane next to the current tiddler I’m viewing or editing)? :thinking:

That’s not about focus. It’s about navigation. If the new-tiddler button is clicked, it creates a new tiddler in edit-mode and navigates to it.

See: ControlPanel → Settings → Tiddler Opening behaviour section

Direct link: Tiddler Opening Behaviour

Since the new-tiddler button is “outside the story river” the Navigation from outside the story river setting is used.

At the moment there is no state, which tiddler has the focus, that’s the best setting I can offer.

If there would be a focused-tiddler in the $:/HistoryList, we wold be able to have additional setting in Navigation from outside the story river eg:

  • Open above focused tiddler
  • Open below focused tiddler

But that’s not possible out of the box atm.

1 Like

Thanks for your explanation, with your hints info, I’ve finally implemented the navigation behavior I wanted: when there are tiddlers A, B, C in the Story River, I give B focus, then click add new tiddler button, the New Tidder will appear below B ➠ A, B, New, C.

Here is how I did it:

❶ Install the Focussed Tiddler plugin by @Sttot from here
❷ Modify the $:/core/modules/widgets/navigator.js like this:

	// Update the story to insert the new draft at the top and remove any existing tiddler
	if(storyList && storyList.indexOf(draftTitle) === -1) {
		// Get the current value of the tiddler in focus
		var focusedPtr = this.wiki.getTiddler("$:/temp/focussedTiddler");
		var focusedTitle = focusedPtr.fields.text;
		var focusedTidIdx = storyList.indexOf(focusedTitle);
		var slot = storyList.indexOf(event.navigateFromTitle);
		if(focusedTidIdx !== -1) {
			slot = focusedTidIdx;
		} else {
			if (slot === -1) {
			slot = this.getAttribute("openLinkFromOutsideRiver","top") === "bottom" ? storyList.length - 1 : slot;
			}
		}
		storyList.splice(slot + 1,0,draftTitle);
	}
	if(storyList && storyList.indexOf(title) !== -1) {
		storyList.splice(storyList.indexOf(title),1);
	}

I know it’s unwise to override shadow tiddlers in $:/core, but for now I don’t know any easier approach to implement this… :sweat_smile:

1 Like

Yes. That’s suboptimal.

Try this: Modify $:/core/ui/Actions/new-tiddler with the following code.

So you do not need to modify a core js-tiddler

\define get-tags() $(textFieldTags)$ $(tagsFieldTags)$
\whitespace trim
<$vars textFieldTags={{$:/config/NewTiddler/Tags}} tagsFieldTags={{$:/config/NewTiddler/Tags!!tags}}>

<$action-createtiddler $basetitle={{$:/language/DefaultNewTiddlerTitle}} tags=<<get-tags>>>
  <$action-listops $tiddler="$:/StoryList" $field="list" $subfilter= "[<createTiddler-title>] +[putafter{$:/temp/focussedTiddler}]"/>
  <$action-sendmessage $message="tm-edit-tiddler" $param=<<createTiddler-title>>/>
</$action-createtiddler>

</$vars>
2 Likes

Thanks again for your code sharing, this is much better than my hacky version! :smiley:

By the way, could I trigger this action $:/core/ui/Actions/new-tiddler from within a JavaScript macro source file? I have installed a contexmenu plugin and it also has a create new tiddler action, I want to use $:/core/ui/Actions/new-tiddler to replace that, is that possible? :thinking:

Below is what I’m using now, whose behavior is inconsistent with $:/core/ui/Actions/new-tiddler

...
  case "tm-new-tiddler":
    this.dispatchEvent({ type: "tm-new-tiddler", paramObject: { title: "$:/pimgeek/draft/new-note", caption: "新笔记" }});
  break;
...

The code-snippet below is not enough context. There must be an event handler somewhere. I thin there are no tm-xxx messages, that can trigger arbitrary action code.

Do you have a link to the code or the modified plugin, that you use atm?

1 Like

Sure! my Digital Garden is publicly accessible, this is the complete JavaScript Macro tiddler: $:/plugins/ahanniga/context-menu/ContextListener.js, this plugin is created by @ahanniga, which was also found in our forum. :smiley: