Good morning Mat,

On Monday, July 13, 2020 at 12:53:05 AM UTC+2, Mat wrote:
>
> This adds an index:
>  
>

Using the Title Picker as an example, if we can do something like this:
<$list filter="[<fragment>minlength[1]]">
<$list filter="[all[tiddlers]prefix<fragment>count[]!match[0]]" 
variable="_NULL">
 <$list filter="""[all[tiddlers]prefix<fragment>]""" variable=name>
 <$button class="tc-btn-invisible tc-tiddlylink">
 <$text text=<<name>>/>
 <$action-sendmessage
 $message="tm-edit-text-operation"
 $param="insert-completion"
 text={{{[<name>addsuffix<trigger-end>]}}}
 precursor=<<fragment>>
 />
 <span data-tw-keyboard-shortcut="Alt+n"></span>
 </$button>
 <br>
 </$list>
</$list>
</$list> 
Where n is the index number in that list, you can use the keyboard 
shortcuts Alt+1, Alt+2, Alt+3 etc.... they will just automatically work. 
But since it would be better to add proper support for keys like arrow keys 
for up and down, enter key etc, don't spend too much time on this.

*Regarding optimizations, performance and refactoring:*

Note that this is the current flow of our code.

(in tiddler *$:/core/ui/EditTemplate/body/editor*)

   - User types in *edit* widget
   - for *every keystroke* edit widget invokes *actions* 
   - actions are in *editorMagicActions* macro and look like: <$
   *action-popupcaret* $state=<<qualify $:/state/EditorMagicPopupState>>/>
   - thus on every keystroke, action-popupcaret is invoked
   - so on every keystoke we trigger a popup (*Reveal* widget)

(in tiddler *EditorMagic/_Popup* )

   - popup (reveal widget) shows this tiddler
   - our list widgets and other wiki text code decide if the popup should 
   have content.
   - If there should be content, we show it. If there should not, we try to 
   hide it by making the popup empty and 0x0 pixels. (it would be more elegant 
   if the popup just wasn't shown in these situations)

This is inefficient because we trigger a popup on every keystroke 
regardless of whether we should show a popup or note. In practice, the 
performance difference is probably neglible. But this is far from elegant 
and is also the reason it is difficult to avoid some of the issues we have 
with the popup appearing at its old position, even though the caret has 
been moved.

Also, this is why adding keyboard shortcuts like using the arrow keys is 
difficult. The keyboard shortcuts need to be applied to the edit widget, 
but all our logic for what is displayed in the popup is in the _Popup 
tiddler. So tying the two together is awkward. 

*Instead I propose we refactor our code for the following flow* (note this 
is all wikitext changes we are discussing here):

   - User types in *edit* widget
   - for *every keystroke* edit widget invokes *actions* 
   - in these actions in *$:/core/ui/EditTemplate/body/editor* we have our 
   wikitext code from EditorMagic/_Popup which checks IF there is a 
   trigger-start that should prompt the showing of a popup. 
      - Only *if* there is a match, do we invoke action-popup-caret.
         - We can also save extra information to the state tiddler, like 
         what text triggered the match, what kind of popup to show (link, 
widget etc)
      - If there is no match, we cancel any already shown popups.
   - When the popup is shown, it reads info from the state tiddler to 
   determine what content to show. All the wikitext related to WHAT to show 
   stays here.

Basically it decouples *detection* code from *display* code.

This may seem like unnecessary at first glance, but it will make it far 
easier to have reliable and predictable behaviour and also be able to add 
keyboard shortcuts for arrow keys.

Cheers,
Saq
 

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/bce9166d-f36b-45b2-bbee-8b0d22b6b861o%40googlegroups.com.

Reply via email to