Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable CodeMirror when on Mobile #2730

Closed
tgrosinger opened this issue Jan 24, 2017 · 7 comments
Closed

Disable CodeMirror when on Mobile #2730

tgrosinger opened this issue Jan 24, 2017 · 7 comments

Comments

@tgrosinger
Copy link
Contributor

@tgrosinger tgrosinger commented Jan 24, 2017

TiddlyWiki version: 5.1.13
CodeMirror version: 5.1.13

The codemirror plugin does not work very well on mobile. Errors pop up frequently and sometimes the written content is even lost. There should be a way to automatically disable codemirror only when on mobile.

This issue is a continuation of this discussion: https://groups.google.com/forum/#!topic/tiddlywiki/Usrl0OQyESY

As noted by @Jermolene, the $:/config/EditorTypeMappings/text/vnd.tiddlywiki tiddler is not wikified when being read for configuration, so changing the value using a mechanism like the $reveal widget is not an option.

@pmario
Copy link
Contributor

@pmario pmario commented Jan 24, 2017

I think, to make this work, we would need to modify the core plugin initialisation. IMO there isn't much, that the user can do atm. except manually disabling the plugin and save / reload. :/

@tgrosinger
Copy link
Contributor Author

@tgrosinger tgrosinger commented Jan 24, 2017

Yeah, that is what @Jermolene indicated as well (a startup module). I might be interested in looking into that, but would need pointers of where to start digging. I have worked in plugin-space a bit, but have not done much in core yet.

@buggyj
Copy link
Contributor

@buggyj buggyj commented Jan 26, 2017

maybe along the lines of

/*\
title: $:/core/modules/macros/hackeditorstring.js
type: application/javascript
module-type: startup


\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

// Export name and synchronous status
exports.name = "hackeditstring";
exports.after = ["load-modules"];
exports.synchronous = true;


exports.startup = function() {


if ($tw.browser)
if (/Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent || navigator.vendor || window.opera)) {
		$tw.wiki.addTiddler(new $tw.Tiddler({title: "$:/config/EditorTypeMappings/text/vnd.tiddlywiki", text: "text"}));
			}
else {
		$tw.wiki.addTiddler(new $tw.Tiddler({title: "$:/config/EditorTypeMappings/text/vnd.tiddlywiki", text: "codemirror"}));
}
}

})();

@tgrosinger
Copy link
Contributor Author

@tgrosinger tgrosinger commented Jan 26, 2017

This works great, thank you @buggyj.

I think it might be good to package this up as a plugin, since not everyone wants this exact behavior. I will look into extending it into something more configurable and generic.

@buggyj
Copy link
Contributor

@buggyj buggyj commented Jan 26, 2017

@tgrosinger - it's just a general idea to get you started, this piece of code does not match the cores' coding style (look at the use of braces and spaces - there is probably a code style guide somewhere), I have no idea if it would capture all smart phones, and if this is applicable for tablets?? So I think there is some work to do yet.

I would expect this functionality to go into the codemirror plugin as you are suggesting.

@PaulHobbs
Copy link

@PaulHobbs PaulHobbs commented Jul 11, 2020

I had to modify the script @buggyj posted to get it working. I replaced $tw.wiki.addTiddler with $tw.wiki.setText on the same already-existing tiddler:


(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

// Export name and synchronous status
exports.name = "hackeditstring";
exports.after = ["load-modules"];
exports.synchronous = true;

exports.startup = function() {
    if ($tw.browser) {
        var w = "$:/config/EditorTypeMappings/text/vnd.tiddlywiki"
        if (/Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent || navigator.vendor || window.opera)) {
            $tw.wiki.setText(w, "text", null, "text");
        }
        else {
            $tw.wiki.setText(w, "text", null, "codemirror");
        }
    }
}

})()

@gabrielmontagne
Copy link

@gabrielmontagne gabrielmontagne commented Jun 2, 2022

Thanks so much, @buggyj and @PaulHobbs. Your hack worked for me perfectly! Great relief!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants