[TW5] Link completion Editor

128 views
Skip to first unread message

Alain Dutech

unread,
Dec 26, 2015, 5:26:25 AM12/26/15
to TiddlyWikiDev
Hello all,

I'm playing with the concept of automated completion of 'links' while editing tiddlers.

A proof of concept is attached and can also be found in http://github.com/snowgoon88/TW5-extendedit

It is not yet in plugin format, but as a stand alone TW5 file. I'm quite new to javascript and TW5 dev so I'm going slowly.

Any comments, suggestions or useful directions are welcome. Should I also post on the 'user' mailing list?

Enjoy your life and the coming year,
Snow/Alain
tw5_one_file.html

Tobias Beer

unread,
Dec 26, 2015, 5:33:11 AM12/26/15
to TiddlyWikiDev
Hi Alain,

Curious to see this work. However, for now I get this:


Best wishes,

Tobias. 

Alain Dutech

unread,
Dec 26, 2015, 5:51:12 AM12/26/15
to tiddly...@googlegroups.com
Well... It works here on Linux+Firefox and Win7+Firefox with the file attached in my first mail.
Compatibility I guess...

Any hints? The error message does not tells where in 'edit-comptext.js' the problem is.
End of lines (Win vs Linux vs Mac) ? Or the fact that I use utf8?

I'll have a look, but not sure I am good enough in javascript/browsers to *quickly* find the error.

I've attached the two javascript file/tiddler I use.

Alain



--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywikidev/BXGldH6YK78/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/245d7c10-89fb-42e0-a066-a2c28a273e09%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

curso_position.js
edit-comptext.js

Alain Dutech

unread,
Dec 26, 2015, 7:35:07 AM12/26/15
to tiddly...@googlegroups.com
Yop, it doesn't work on chromium-browser + Linux
But I have no clue.

Alain

Tobias Beer

unread,
Dec 26, 2015, 10:05:56 AM12/26/15
to TiddlyWikiDev
Forgot to mention,I get the error on both WIN10 or Vista + Chrome.
Works in Firefox, sort of. Would be nice to be able to access the popup using (arrow) keys, rather than the pointer.

Best wishes,

Tobias.

BJ

unread,
Dec 26, 2015, 8:27:45 PM12/26/15
to TiddlyWikiDev
Hi Alain,
the statement (default function parameter ) is not supported by chrome until version 49 according to firefox so
nbMax=2
is causing the problem

all the best

BJ

Alain Dutech

unread,
Dec 27, 2015, 4:58:31 AM12/27/15
to tiddly...@googlegroups.com
Oh, thanks a lot BJ.
I'll send you another version soon. Taking care that is works also on Chrome :o)

Alain

Alain Dutech

unread,
Dec 27, 2015, 5:13:18 AM12/27/15
to tiddly...@googlegroups.com
Okay, this one works on Linux + (Firefox/Chrome), Win7+Firefox... Not tested others.

What I will consider in the (near) futur :
 - proper plugin
 - using arrows to select one choice among the listed choices. => I guess I'll have to dynamically change the css style of the element in my popup window to achieve this ?

Still a lot to learn :o)

Alain


tw5_one_file.html

Felix Küppers

unread,
Dec 27, 2015, 7:35:05 AM12/27/15
to tiddly...@googlegroups.com
Hi Alain,

very glad you picked this up.

Would be great if you could also add an autocompletion trigger. When I
am inside a word that starts with `[[abc` and I hit a keycombo, then the
list pops up with tiddler names matching "abc".

In IDEs (Eclipse, Netbeans, Atom, Geany etc.) it is a convention to have
ctrl+space trigger autocompletion. But preferably users could pick their
own hotkey.

For a way to add keycombos, it may be worth considering to extend the
textwidget (have a look at Danielo's hotkeys widget:
https://github.com/danielo515/TW5-KeyboardSnippets/blob/master/wiki/plugins/extendTextWidget/keyboardSnippets.js#L20).
However, the postRender function is a bit problematic as it can only be
overridden once…

> What I will consider in the (near) futur :
> - using arrows to select one choice among the listed choices. => I
> guess I'll have to dynamically change the css style of the element in
> my popup window to achieve this ?

Yes, and you need to store the selection index internally of course.

> Still a lot to learn :o)

I think this plugin is not easy to implement so take your time! ;)

-Felix

Alain Dutech

unread,
Dec 28, 2015, 3:39:47 AM12/28/15
to tiddly...@googlegroups.com
@Felix : thx for the suggestion and the link to Danielo's work.

@All : I have a problem "compiling" my files into a proper plugin

~/Projets/TW5[master]
=> nodejs ./tiddlywiki.js editions/tw5.com --build index
Error executing boot module $:/plugins/snowgoon88/edit-comptext/edit-comptext.js:
Error: Cannot find module '$:/plugins/snowgoon88/edit-comptext/cursor-position.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.$tw.modules.execute (/home/dutech/Projets/TW5/boot/boot.js:695:11)
    at sandbox.require (/home/dutech/Projets/TW5/boot/boot.js:654:24)
    at $:/plugins/snowgoon88/edit-comptext/edit-comptext.js:21:27
    at $:/plugins/snowgoon88/edit-comptext/edit-comptext.js:442:3
    at $tw.utils.evalSandboxed (/home/dutech/Projets/TW5/boot/boot.js:450:5)
    at Object.$tw.modules.execute (/home/dutech/Projets/TW5/boot/boot.js:707:15)

Question : where are the plugins files taken from ? my local hard drive or directly on "my"github, master branch ?

Here is hat I did :

1) edited TW5/editions/tw5.com/tiddlywiki.info to add "snowgoon88/edit-comptext" in the "plugins" array.

2) in the TW5/plugins/snowgoon88/edit-comptext directory
2.1) one edit-comptext.js file that start with
/*\
title: $:/plugins/snowgoon88/edit-comptext/edit-comptext.js
type: application/javascript
module-type: widget

Taken from original Edit-text widget
Version 5.1.9 of TW5
Add link-to-tiddler completion

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
   
var DEFAULT_MIN_TEXT_AREA_HEIGHT = "100px"; // Minimum height of textareas in pixels
   
var Widget = require("$:/core/modules/widgets/widget.js").widget;
// to compute pixel coordinates of cursor
var getCaretCoordinates = require("$:/plugins/snowgoon88/edit-comptext/cursor-position.js");
....

2.2) one "plugin.info" file with
{
        "title": "$:/plugins/snowgoon88/edit-comptext",
        "description": "Editor with some on-line completion capabilities",
        "author": "AlainD",
        "version": "1.0",
        "core-version": ">=5.0.8",
        "source": "https://github.com/snowgoon88/TW5-extendedit",
        "plugin-type": "plugin",
        "list": "readme"
}


3) in the directory TW5/plugins/snowgoon88/edit-comptext/files
3.1) one "tiddlywiki.files" with
{
        "tiddlers": [
                {
                        "file": "cursor-position.js",
                        "fields": {
                                  "type": "application/javascript",
                                  "title": "$/plugins/snowgoon88/edit-comptext/cursor-position.js",
                                  "module-type": "library"
                        }
                }
        ]
}

3.2) one "cursor-position.js" file

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywikidev/BXGldH6YK78/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.

Alain Dutech

unread,
Dec 28, 2015, 3:53:37 AM12/28/15
to tiddly...@googlegroups.com
Sorry... too fast. Taking some steps outside gave me the solution : I forgot some ":" at a file name.

But, another problem :
In node.js, the following line is causing problem
var isFirefox = window.mozInnerScreenX != null;

because, I guess, the global var window is only defined if using a browser.

What is the usual way of dealing with this within node.js ??

Thx,
Alain

Felix Küppers

unread,
Dec 28, 2015, 9:02:08 AM12/28/15
to tiddly...@googlegroups.com
Hi Alain,


because, I guess, the global var window is only defined if using a browser.

What is the usual way of dealing with this within node.js ??

It is not good style that the lib assumes the window object exists while it is loaded. Not sure how you can solve this.

I would suggest you replace the occurence of isFirefox (https://github.com/snowgoon88/TW5-extendedit/blob/df28ef2044a24cb4804af2037719ec08c7b68640/files/cursor-position.js#L91) with window.mozInnerScreenX != null; and remove the variable so it is only evaluated at runtime.

Maybe @Jeremy or somebody else can provide a better answer.

Also have a look at the use of $tw.browser in some of the tw lib plugins:

https://github.com/Jermolene/TiddlyWiki5/blob/72941f3e9a916948222ff7be540d896e2b1901f6/plugins/tiddlywiki/codemirror/edit-codemirror.js#L31

In startup modules you usually say:

exports.platforms = ["browser"];

Good luck.

-Felix

Alain Dutech

unread,
Dec 28, 2015, 10:48:25 AM12/28/15
to tiddly...@googlegroups.com
@Felix : thank you a lot, indeed. I've used $tw.browser.

And now, the version 1.0 of the plugin is officially available to try and download at
http://snowgoon88.github.io/TW5-extendedit

And the source is at
https://github.com/snowgoon88/TW5-extendedit/

Enjoy, comment and critic :o)
Alain


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywikidev/BXGldH6YK78/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.

Felix Küppers

unread,
Dec 28, 2015, 1:15:47 PM12/28/15
to tiddly...@googlegroups.com
Hi Alain,

Nice that $tw.browser was what you needed.

Following your instructions using FF and Chrome on Linux didn't work in your latest demo, nothing happened :(

-Felix
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 tiddlywikide...@googlegroups.com.

To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.

Alain Dutech

unread,
Dec 28, 2015, 1:21:57 PM12/28/15
to tiddly...@googlegroups.com
Ah, damn, I forgot to tell that a small configuration is required for the editor to kick in...

In $:/ControlPanel -> Advanced -> Editor Type -> text/vnd.tiddlywiki
you must chose comptext instead of text.

I'll add it at once.

Alain

Reply all
Reply to author
Forward
0 new messages