Another Caret issue?

42 views
Skip to first unread message

TonyM

unread,
Jul 11, 2020, 8:32:55 PM7/11/20
to TiddlyWikiDev
Folks,

Given the Caret questions in the dev forums I thought it timely to ask another question on this.

It has often being asked with a view mode "click to edit" if the cursor could be placed in the editor in the same location as one clicked. 
  • Unfortunately this usually misses the fact that much of the display can be rendered and not necessarily existing inside the tiddler (eg was transcluded)
I have recently made a "smart" showcode view and with help its wrapped in a button and we can click to edit a display of code.
  • Why smart? 
    • It users a range of factors if the code should be displayed by default.
    • Whether code is displayed can be overridden without touching the tiddler in question eg shadow tiddler.
  • In the case of displaying code the click position should readily map to a position in the editor since no wikitext rendering is one code display.
So the question is!

At least in the case of clicking on code, displayed as it is, in a raw form. Can we capture the click position and place the cursor at that position in edit mode?

I have no understanding of the methods for this but It would make coding tiddlywikis much easier, at present editing a complex macro can involve a lot of scanning to locate places to make changes, and unfortunately once you edit you have to do it again.

Thanks
Tony


Mat

unread,
Jul 12, 2020, 8:21:59 AM7/12/20
to TiddlyWikiDev
[This is beyond me but anyway]

I'm thinking each "special rendering" such as a list, a transclusions etc will have to be identified as one unit when clicked on. So even if the caret position in view mode is calculated, this position - say 200 - could be after a few transclusions meaning that it in the code is really only position 20. To know that 180 has to be deducted, means one has to identify and calculate the character lengths of those transclusions. Including possible transclusions inside those transclusions, etc.

But maybe one can go the other way; start by peeking into the wikitext in the editor. There could be a "faux caret character" (for lack of better term) set inside the wikitext that shows up in view mode. If this caret could be steered, e.g via arrow keys (to type/delete it as it "steps") one could manually move it to where one wants to edit and "click enter" to switch to edit view - and with a positioned caret. Buuuut positioning the faux caret like that sounds like more work than just entering edit mode and searching up the correct position. So steering the faux caret would need a better way, perhaps ideally by having it "follow the mouse". And that's where I've twaddled enough ;-)

<:-)

TonyM

unread,
Jul 12, 2020, 8:58:11 AM7/12/20
to TiddlyWikiDev
Mat

I value your ideas but the key point to my post was when we display the code, rather than rendered text. What I mean by that is using a custom view template on tiddlers that contain macros etc but viewed as we view in edit mode, unrendered.

I will try and put my beta smart show code up tomorrow to illustrate this.

Its a far simpler to do than what you are trying to tackle.

Regards
Tony

Mat

unread,
Jul 12, 2020, 9:42:36 AM7/12/20
to TiddlyWikiDev
Well, putting the caret at correct position in the editor is what I was talking about too. But i figure the position in the editor needs to map the position you're clicking at in view mode - so you need a way to decide where that is. Anyway, I obviously don't know anything about this.

using a custom view template on tiddlers that contain macros etc but viewed as we view in edit mode, unrendered.


A viewtemplate that show the wikitext code... OK so for it to be useful, how do you go from normal edit view into this view? And is that simpler/faster than to just find the location the manual old fashioned way? Because that is the goal, right?, to quickly access a specific position in the editor.

<:-)

TonyM

unread,
Jul 12, 2020, 9:02:18 PM7/12/20
to TiddlyWikiDev
Mat,

My showcode demo is a still a few hours away for putting online, otherwise I would confuse people.

Anyway, I obviously don't know anything about this.

Not true, its just what I am looking for is a subset of this larger question.  
The cursor position on a plain text un-rendered view, which should be easier and there is a one for one match between positions.

To summarise my smart showcode utility makes a good guess if the content of the tiddler is code rather than something to render, such as ones macro definitions, using a number of qualities, if it is a "code tiddler" it displays that code as plain text. For example open a system tiddler that has not being edited and you get a plain text display you can select and copy from without "editing the tiddler" just to see the content, To avoid unnecessary edits to shadow tiddlers, you need to explicitly use the edit button to edit it. 

If however you open an overwritten shadow tiddler, or a code tiddler of your own making, you see the plain text (show code view) and have a click to edit feature. It is this click to edit I would like to allow to determine where in the plain text view you click, and restore the cursor to that position in the edit view.

Advanced search and Control panel as examples, are system/code tiddlers you want rendered, so I provide a way to override the showcode not to display on these.

So say I am looking through core code to find the actions message or widget used to do something, I search system tiddlers and get three hits, so I open these three, and they are all readable at first glance because they are code tiddlers. I find the action widget I was after and select and copy the code, now I return to my own code tiddler, the one I am developing, scan through to find where I want to insert the code and click exactly where I want, to insert the new action, and click, the tiddler goes into edit mode and the cursor is where I clicked, ctrl-V to insert and I am done. 

Perhaps one day one could even insert in that position without going into edit mode. This would allow drag and drop coding nice and easy.

To make this even easier, I would add the search highlight plugin to help in the code search.

I hope this explains the use case?

Regards
TW Tones

TonyM

unread,
Jul 12, 2020, 9:09:07 PM7/12/20
to TiddlyWikiDev
Post script

This endeavour is part of a larger one to obtain the tools to support rapid development on top of the tiddlywiki platform. Removing any barriers, unnecessary steps or cognitive barriers to design.

Regards
TW Tones
Reply all
Reply to author
Forward
0 new messages