Hi Vincent,
> Now, the "boring" part.
>>
>> 1. create a one-line tiddler with text alpha __beta__ gamma. Click to
>> edit the only block. Add a new line (enter) and apply (ctrl+enter). Enter
>> the ordinary edit mode (click "edit"). Press esc to cancel. What is
>> expected: the changes are already applied, and since I haven't changed
>> anything in the ordinary edit mode I will just leave. What actually
>> happens: the editor asks if we should leave without saving changes (as
>> thought as they were done in the edit mode, not in twve).
>>
>
> I think that's because the tiddler was not saved after the new-line being
> added. This behavior is of TiddlyWiki (without AutoSave), not of *twve*.
>
> Not quite. The thing about autosave is what would be on leaving TW, not
the tiddler edit mode. This looks like no store.notify was called (and
hence no store.saveTiddler was called) and because of that no refreshing
was done, though I'm not totally sure.
Recently I've came to an idea how to create a formatter that can create an
editable text and save changes back to wikitext. The main idea is to use
such engine for MathQuill [1] in TWc which I've already implemented to some
extent, but here I'll just show the template for such formatter, may be
you'll find this useful. Now I understand TWc Wikifier relatively well, so
if you have some questions, I'll probably be able to answer. So here's the
text of the tiddler containing a test, the code and some comments:
/***
|Version|0.9|
A simple formatter is implemented here. This formatter creates DOM that can
be "reflexively edited": editing changes not only DOM, but also wikitext
which it was generated from.
|test formatter|<ff>val 3</ff> (was: {{{<ff>val 2</ff>}}})|
* recalcs slices (changes are applied); refreshing doesn't affect
distructively; several consiquent edits via one formatter work correctly
* ''test'' several edits via several formatters; test with transclusion,
including sections (both should work correctly)
***/
//{{{
var reflexiveFormatterTerm =
{
name: "reflexiveFormatterTest2",
openWrapper: "<ff>",
closeWrapper: "</ff>"
};(function($){ // concatenate to reflexiveFormatterTerm ($ = this)
$.match = $.openWrapper;
$.lookaheadRegExp = new RegExp($.openWrapper + "(.*?)" +
$.closeWrapper, "mg");
$.handler = function(w)
{
$.lookaheadRegExp.lastIndex = w.matchStart;
var wholeThingMatch = this.lookaheadRegExp.exec(w.source);
if(!wholeThingMatch) return;
// wikitext "corresponding to the formatter" with wrapper
var wholeThing = wholeThingMatch[0],
// wikitext "corresponding to the formatter" without wrapper
mainThing = wholeThingMatch[1];
w.nextMatch = this.lookaheadRegExp.lastIndex;
var sourceTiddler = w.tiddler,
startPosition = w.matchStart,
initialLength = w.matchLength;
var changeWikiText = function(newText)
{
// prepare texts and positions
var noTiddlerMsg = "changeWikiText: no sourceTiddler detected";
if(!sourceTiddler)
return console.log(noTiddlerMsg);
var endPosition = startPosition + wholeThing.length;
wholeThing = $.openWrapper + newText + $.closeWrapper;
mainThing = newText;
// change wikitext to newText
sourceTiddler.text =
sourceTiddler.text.substr(0,startPosition) +
wholeThing +
sourceTiddler.text.substr(endPosition);
//# any change of sourceTiddler.text outside without refreshing can break
the engine
// (when the length of the text before matchStart is changed)
store.saveTiddler(sourceTiddler); // recalcs slices, notifies
etc
// .oO about "no refresh" approach (change w.nextMatch,
// presumably using the difference between ..; change textNode)
// can search for the wholeThing and replace it
// drawback: will work correctly only if there's no
"duplicates"
// correct approach should probably involve a special
// "backward wikifier" object which remembers where wikitext
// matched by each formatter begins and which we can change
// when we change wikitext corresponding to our formatter
}
// do the DOM stuff
createTiddlyButton(w.output,"click to test","",function(){
changeWikiText(prompt("let's change this!",mainThing));
});
var textNode = createTiddlyText(w.output,mainThing);
}
})(reflexiveFormatterTerm);
config.formatters.push(reflexiveFormatterTerm);
//}}}
If that's interesting, I can share the apply-MathQuill code as well.
Best regards,
Yakov.
[1] http://mathquill.com/ , there's nice demo on the main page
PS Hi *Hegart* and *c pa*, I think, since this thread is used for
discussing *twve* for quite some time, it would be nice if you move the
discussion of another engine to another thread. I mean no offence, it's
just seems too offtopic now.
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/4df74b2a-bc2d-42b0-b4ed-6e34022abece%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.