TiddlyWiki / TiddlyWiki5

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

[IDEA] Toggle browser spell-checker on a per tiddler editor basis #6927

Open pmario opened 2 years ago

pmario commented 2 years ago

The request comes from: https://talk.tiddlywiki.org/t/turn-off-spellcheck/4378

It's requested to toggle the browser spellchecker on a per tiddler-editor basis with a keyboard shortcut or a toolbar button. There should be a small spell-check indicator too

It should be relatively straight forward. https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck

Jermolene commented 2 years ago

Thanks @pmario that's a good idea.

amreus commented 2 years ago

I've been digging into this. What is the preferred strategy here?

To add a "spellcheck" or similarly named attribute to the EditTextWidget?

amreus commented 2 years ago

Work so far: https://github.com/Jermolene/TiddlyWiki5/compare/master...amreus:TiddlyWiki5:toggle-spellcheck

amreus commented 2 years ago

Or maybe ContentType could be used to enable/disable spellchecking?

Jermolene commented 2 years ago

Hi @amreus

To add a "spellcheck" or similarly named attribute to the EditTextWidget?

Yes I think that makes sense.

The OP asks for a per-tiddler setting, but I'm not sure that it's worth the visual clutter. I'd also rather avoid adding new UI strings for this, so perhaps it could be a hidden setting.

amreus commented 2 years ago

Yes I think that makes sense.

Ok. I'm still trying to get a grip on the internals but will continue to study.

The OP asks for a per-tiddler setting

I'm the OP. I didn't mention a per-tiddler setting, in fact I mentioned that a global per-wiki setting would be my preference. But if the setting is per wiki, then it would seem a new widget attribute would be unnecessary?

Jermolene commented 2 years ago

I'm the OP. I didn't mention a per-tiddler setting, in fact I mentioned that a global per-wiki setting would be my preference. But if the setting is per wiki, then it would seem a new widget attribute would be unnecessary?

We should still implement it via a new attribute for flexibility.

amreus commented 2 years ago

Just an update and note for myself and comments.

Spellchecking defaults to "yes".

There may exist a config tiddler named $:/config/TextEditor/Spellchecking with accepted values of "yes" and "no". The edit-widget looks to this tiddler to enable/disable spellchecking. If the tiddler exists and its text field is set to "no", only then is spellchecking disabled for the dom element (textarea).

The above global Spellchecking is over-ridden by a spellchecking attribute of the edit-text widget if it is used.

Sound right?

Jermolene commented 2 years ago

Sound right?

Yes, thank you @amreus. Let me know if you run into any blocks.

amreus commented 2 years ago

I did not do any sort of UI, but the diffs can be viewed here:

https://github.com/Jermolene/TiddlyWiki5/compare/Jermolene:TiddlyWiki5:master...amreus:TiddlyWiki5:spellchecking

If it's headed in the right direction, I can do a pull request.

This can be used as a toggle for test.

$:/config/TextEditor/Spellchecking enabled? <$checkbox
tiddler="$:/config/TextEditor/Spellchecking" field=text checked=yes
unchecked=no default=yes> {{$:/config/TextEditor/Spellchecking}}</$checkbox>
pmario commented 2 years ago

I think the refresh mechanism needs to check against attribute changes and config-tiddler change.

amreus commented 2 years ago

I think the refresh mechanism needs to check against attribute changes and config-tiddler change.

I did wonder about that. Out of curiosity, what is the scenario where the attribute change is what causes a refresh?

pmario commented 2 years ago

I did wonder about that. Out of curiosity, what is the scenario where the attribute change is what causes a refresh?

If I use my own config tiddler and connect it to the widget call.


In principele, it doesn't really matter. If the attribute is there, there is a chance that it will change. So the refresh-handling has to be there.

amreus commented 2 years ago

I think the refresh mechanism needs to check against attribute changes and config-tiddler change.

Ok added. I also squashed the silly minor commits.

Tony asked a question about using this with codemirror plugin. I didn't have a good answer about that. Is it an problem?

Diffs

pmario commented 2 years ago

Tony asked a question about using this with codemirror plugin. I didn't have a good answer about that. Is it an problem?

There has been a discussion at GG and a workaround was suggested, that I think is perfectly fine.

See: https://github.com/Jermolene/TiddlyWiki5/issues/5841 and: https://groups.google.com/g/tiddlywiki/c/PwoBZHggN2s/m/XGUnRTTNAgAJ

Other open Issues: https://github.com/Jermolene/TiddlyWiki5/issues?q=is%3Aissue+is%3Aopen+spell+check

pmario commented 1 year ago

Some time ago I found out, that CM5 has an option to turn on spellchecking. https://codemirror.net/5/doc/manual.html search for "spellcheck"