TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.05k stars 1.19k forks source link

[BUG] Dragging tiddler links inconsistently wraps titles in double square brackets #7405

Open Jermolene opened 1 year ago

Jermolene commented 1 year ago

Describe the bug

Dragging a title link of a tiddler with a space in the title into a text area will create a link to that tiddler by wrapping the title in double square brackets. However, dragging a title link of a tiddler that does not have a space in the title into a text area will not wrap the title in double square brackets and thus will not create a link.

This behaviour occurs because of the use of $tw.utils.stringifyList() in dragndrop.js:

https://github.com/Jermolene/TiddlyWiki5/blob/23b5b7f7d9abafcec4e357b154319ee7ab187704/core/modules/utils/dom/dragndrop.js#L128

Expected behavior

The expected behaviour is that dragging a tiddler title into a text area will always wrap each title in double square brackets to make it act as a link.

There is a thread on talk.tiddlywiki.org where a user requests the option to wrap dragged titles in double braces (for transclusion) instead of double square brackets, and that seems a reasonable option to support

To Reproduce

  1. Go to https://tiddlywiki.com/
  2. Click the "new tiddler" button in the sidebar
  3. Click the "done" button to create a new tiddler called "New Tiddler"
  4. Click the "new tiddler" button in the sidebar again to create a draft tiddler called "Draft of 'New Tiddler 1'"
  5. From the "Open" tab in the sidebar, drag the link to "New Tiddler" into the editable text area for the new tiddler
  6. Notice that the text "[[New Tiddler]]" including double square brackets is inserted into the text area
  7. From the "Open" tab in the sidebar, drag the link to "HelloThere" into the editable text area for the new tiddler
  8. Notice that the text "HelloThere" without square brackets is inserted into the text area

Screenshots

No response

TiddlyWiki Configuration

TiddlyWiki v5.2.7

Additional context

No response

saqimtiaz commented 1 year ago

See #6317 which also requests consistency in applying square brackets.

Dpeneding on how we address this, there might be backwards compatibility implications for use of the draggable widget.

pmario commented 1 year ago

I think that's an issue now since we disabled automatic wiki-links for new wikis. ...

I personally do like this default behaviour and we should not change it. I use the drag from Open sidebar mainly to drag tiddler titles into tag-like fields. For tags we need [[New Tiddler]] but we do not need [[HelloThere]]

I think that's the way how it was initially intended to work.

Instead I do propose that we add modifier-keys eg: SHIFT, CTRL and ALT to create different type of links. So it would be possible eg:

and so on

pmario commented 1 year ago

I did some more testing. For tags, it does not matter if HelloThere has braces or not. The tag field removes them.

For standard fields, we need to have a closer look what filter operators like enlist or enlist-input return if they are fed with [[HelloThere]] instead of HelloThere as it is now. I don't know that atm

Jermolene commented 1 year ago

Hi @pmario the current behaviour is nothing to do with automatic wikilinks; it's the function "stringifyList()" (referenced in the OP) that adds the double square brackets purely according to whether the title contains whitespace.

The idea of using modifier keys is not universal because it won't work on touch devices.

pmario commented 1 year ago

I think this issue is also related to: [IDEA] Option to make drag and dropping tiddler titles (shown as a link) always make a link #6317

which mentions: [IDEA] In editor, drop image-link to create an external link #5309

As I wrote in #6317, the title string that is dropped into a text-area is created at the drag-start which is line: https://github.com/Jermolene/TiddlyWiki5/blob/23b5b7f7d9abafcec4e357b154319ee7ab187704/core/modules/utils/dom/dragndrop.js#L49

And it's the dataTransfer object text/plain text that is passed to the text-input for import.

https://github.com/Jermolene/TiddlyWiki5/blob/23b5b7f7d9abafcec4e357b154319ee7ab187704/core/modules/utils/dom/dragndrop.js#L107

Just an idea

For very fine grained control for desktop and mobile

It may be possible to set a tv-dnd-start="titlelist" variable, which imo would be in line with the format:titlelist operator suffix.

For mobile and desktop

The utility.makedraggable() function could read the tv-dnd-* variables and act according to their value. eg:

Possible tv-dnd- variables

For desktop


utility.makedraggable() ... DnD-dragend may have similar possibilities with tv-dnd-end-<you-name-it>

Jermolene commented 1 year ago

Hi @pmario rather than supporting a fixed list of transformations such as title, transclusion, templatelist etc. we could instead have a configuration variable that contains a function that is executed to convert the title of a tiddler at the point that it is dragged into the text that the receiving application sees. For example:

\function tv-dnd-incoming-title-transformation(title) [<title>addprefix[{{]addsuffix[}}]]