[Release] Codemirror6 Plugin

https://tiddlywiki.com/#EditWidget

Sorry, it is a widget

https://imgur.com/a/41Ye9wE

So you’ve applied CM6 directly to the $edit widget? Is there a way to turn it off for a given instance?

cm6 just imitates the usage of cm5. if you dont want to use cm6, you should use edit-text widget

Not sure why you’re asking me that… I have every intention of using it.

Let me ask you again… it seems from your previous response that CM6 is enabled on every $edit widget. In that case, is there a way to disable CM6 on a specific $edit if I have a need to do so?

CM5 didn’t work like that. As far as I understood, it was applied only to the regular tiddler editor, i.e., tiddlers in edit mode.

So, again, if CM6 is applied to ALL edit widgets, can is be turned off for a specific instance:


<$edit cm6="no" ... />

or, perhaps...

<$let cm6-enabled=no>
<$edit ... />
</$let>

Sorry, I haven’t figured out this part yet. I will continue to look at it carefully.

The cm6 plugin does not directly modify the edit.js file. cm5 does not seem to support disabling on edit widget. Can you give an example of disabling edit with codemirror5?

No, because I could never get it to work in ad hoc edit widgets. Like I said, it only worked in the tiddler editor.

@CodaCoder This is a well known limitation of codemirror5 and its not surprising its a problem in codemirror6. The way it effectively replaces the core editor makes it hard to toggle between the two. You have to disable the codemirror plugin and reload.

Before codemirror6 provided spell check support, I create a new preview that one could open in the editor to have access to the tiddler text using the $edit widget, treating it as a simple text area allowed spell check to work.

  • Just ask if you want this previewer.

Here is some research to “fix code mirror” to allow the standard editor

There are three approaches I can see to address this;

  • The StoryTiddler cascade mechanism is new since the original codemirror and is possibly a way to achieve this
  • Change the codemirror design to permit a choice on tiddlers between codemirror and standard edit.
    • Making codemirror use the story tiddler cascade mechanisium would be wise, but codemirror possibly outside my skill set, or maybe not.
    • Although we may only need to modify the following in the package
      • $:/core/ui/EditorToolbar/preview
      • $:/core/ui/EditTemplate/body/default
      • $:/core/ui/EditTemplate/body/editor
    • however codemirror also modified many of the the tiddlers [prefix[$:/core/modules/editor/operations]] are these compatible with the standard editor?
  • Make a clone of the core tiddlers used by the standard editor before codemirror is installed and present an option to use the standard edit as an alternative. Perhaps using a new story tiddler cascade.

The second is within my skill set, but I think it would be better for codemirror to address this, because it causes the issue.

Code mirror is great but when publishing a wiki for novice users asking them to use a sophisticated editor is too much to expect. I can see value having codemirror on code and standard editor otherwise. Or alternative settings per tiddler or group of tiddlers.

1 Like

I added such a configuration item. As you said, the operation file uses some methods provided by codemirror6. In this case, using the operation toolbar will cause errors. I currently have no good solution except suppressing these errors. Pop-ups.

At the same time, changing this configuration also requires a restart. I think it is better to disable cm6 directly.

We could stop code mirror, overwriting any of the $:/core/modules/editor/operations/text/... and create new ones, then build a new set of editor toolbar buttons that reference the new ones, for used in the codemirror editor. eg instead of excise we have a cm-excise text operation.

When it comes to the following;

  • $:/core/ui/EditorToolbar/preview
  • $:/core/ui/EditTemplate/body/default
  • $:/core/ui/EditTemplate/body/editor

We could look at getting the core to change to accommodate cloud mirror without edit, or an edit of these could be rewritten to accomodate access to the standard edit.

  • I have not analysed the config tiddlers yet.

As I said before, switching to simple editor (textarea) requires refreshing tiddlywiki, which is no different from disabling cm6 directly and use edit-text widget

tiddlywiki-codemirror6 plugin 1.1.0 have better performance for IME

IME ? what does this mean?

The $edit widget creates the appropriate editor widget for the tiddler type based on the value of the corresponding $:/config/EditorTypeMappings tiddler. To create a default edit text widget, it can be called directly <$edit-text....

Currently changing the editor type mapping for a given tiddler type does not refresh any open editors. I have created a draft PR that should resolve this and allow switching the editor type by changing the value of the editor type mapping tiddler.

@oeyoews could you please test if this is helpful? With this in place a simple editor toolbar button that toggles for example the value of the tiddler $:/config/EditorTypeMappings/text/vnd.tiddlywiki between edit and codemirror6 should switch editors for all tiddlers being edited that have the type text/vnd.tiddlywiki.

3 Likes

Thank you @saqimtiaz, that has flummoxed me for too long.

What does it do with a blank type field? Does it default to text/vnd.tiddlywiki ?

yes

Screenity video - Jan 23, 2024

1 Like

I added an editortoolbar for switching editor type, the code is very rough and not very standard (I rarely write wikitext)

title: $:/plugins/oeyoews/tiddlywiki-codemirror-6/ui/EditorToolbar/toggleEditor
tags: $:/tags/EditorToolbar
custom-icon: yes
caption: Toggle Editor
description: toggle editor
condition: [<targetTiddler>!has[type]] [<targetTiddler>get[type]!prefix[image/]] [<targetTiddler>get[type]match[image/svg+xml]]
icon: $:/plugins/oeyoews/tiddlywiki-codemirror-6/icon

\whitespace trim
\define prefix() $:/config/EditorTypeMappings/

\define defaultType() text/vnd.tiddlywiki

[img width=16 [$:/plugins/oeyoews/tiddlywiki-codemirror-6/icon]]

<% if [<targetTiddler>get[type]count[]match[0]] %>
<$action-listops $tiddler={{{ [<defaultType>addprefix<prefix>] }}} $field="text" $subfilter="+[toggle[codemirror-6],[text]]" />
<% else %>
<$action-listops $tiddler={{{ [<targetTiddler>get[type]addprefix<prefix>] }}} $field="text" $subfilter="+[toggle[codemirror-6],[text]]" />
<% endif %>

Can this code be simplified? It mainly handles the case where type is empty.

Screenity video - Jan 23, 2024 (1)