We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28215
    • 4,149 Posts
    This is an auto-generated topic for CodeMirror 1.0.1-pl by splittingred.

    Brief Description:

    CodeMirror integration for MODx Revolution. Get custom syntax highlighting in your Elements.
    New in 1.0.1

    • Now auto-assigns CodeMirror to which_element_editor setting


      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
      • 3749
      • 24,544 Posts
      This is a great addition to MODx, but I noticed a couple of minor issues:

      1. When updating from 1.0.0 to 1.0.1 (using right-click in PM), I see the whole GPL in the console during the update. [Update: This isn’t a CodeMirror issue, I’m seeing it will other packages as well). http://svn.modxcms.com/jira/browse/MODX-2151 ]

      2. CodeMirror is still flagging some of its own code as erroneous (lines 18-22).

      [Update] The CM PHP parser doesn’t like casts. I contacted the creator but he got the PHP parser from someone else and doesn’t plan to rewrite it.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 23491 ☆ A M B ☆
        • 1,056 Posts
        Awesome work!! I’ve been meaning to look into an EditArea replacement, and CodeMirror was my top choice. Great work on the transport package smiley

        I’m having a bit of a hard time trying to get it to work when editing Resources...

        Would it be related to the empty "OnRichTextEditorInit" block in the CodeMirror plugin (+activating the system event), or would it need it’s own case-statement for "OnDocFormPrerender"?

        Also, I am curious how
        $options[’modx_loader’]
        is used? (onSnippet, onChunk, onTV, etc)... I presume I will need to know the connection in order to get CodeMirror to run when editing a Resource...

        Example attempt:

        Quote from: "CodeMirror

        case ’OnDocFormPrerender’:
        $options[’modx_loader’] = ’onDoc’; // ??
        $modx->regClientCSS($assetsUrl.’css/cm.css’);
        $modx->regClientStartupHTMLBlock(’<script type="text/javascript">MODx.codem = ’.$modx->toJSON($options).’;</script>’);
        $modx->regClientStartupScript($assetsUrl.’cm/js/codemirror.js’);
        $modx->regClientStartupScript($assetsUrl.’js/cm.js’);
        break;


        Update:

        Ah-ha! I found the modx_loader references in core/packages [...] codemirror/js/cm.js:

                ,onChunk: function() {
                    return Codem.init('modx-chunk-snippet','modx-panel-chunk');
                }
                ,onPlugin: function() {
                    return Codem.init('modx-plugin-plugincode','modx-panel-plugin');
                }
                ,onSnippet: function() {
                    return Codem.init('modx-snippet-snippet','modx-panel-snippet');
                }
                ,onTemplate: function() {
                    return Codem.init('modx-template-content','modx-panel-template');
                }
                ,onTV: function() {
                    return Codem.init('modx-tv-default-text','modx-panel-tv');
                }
        



        ...clearly my guess at "onDoc" will not work. Further, I was able to set "which_editor" in System Settings to use CodeMirror, but unfortunately the editor fails to load when editing a resource.
          Mike Reid - www.pixelchutes.com
          MODx Ambassador / Contributor
          [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
          ________________________________
          Where every pixel matters.
          • 28215
          • 4,149 Posts
          That’s because I haven’t finished the code for CodeMirror to work with Resources. wink
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 23491 ☆ A M B ☆
            • 1,056 Posts
            Quote from: splittingred at Jul 27, 2010, 09:02 PM

            That’s because I haven’t finished the code for CodeMirror to work with Resources. wink

            Well that makes sense...yet it seemed SO close! I guess I’ll just have to wait for 1.0.2-pl smiley

            Out of curiosity, is there anything specific to Resources that you think would make this task more difficult than say, Snippets/Chunks/Plugins?


            Quote from: BobRay at Jul 15, 2010, 12:00 AM

            [Update] The CM PHP parser doesn’t like casts. I contacted the creator but he got the PHP parser from someone else and doesn’t plan to rewrite it.

            @BobRay, that’s too bad sad I frequently typecast in PHP and would be disappointed having to see red, erroneous false-alarms in CodeMirror.
              Mike Reid - www.pixelchutes.com
              MODx Ambassador / Contributor
              [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
              ________________________________
              Where every pixel matters.
              • 28215
              • 4,149 Posts
              Quote from: pixelchutes at Jul 28, 2010, 02:59 PM

              Out of curiosity, is there anything specific to Resources that you think would make this task more difficult than say, Snippets/Chunks/Plugins?
              Yes; Resources have TVs which load via AJAX, plus the code for loading an RTE is a bit different, and you’ll have to know what to do when TinyMCE is installed as well.
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 23491 ☆ A M B ☆
                • 1,056 Posts
                Quote from: splittingred at Jul 28, 2010, 03:12 PM

                Quote from: pixelchutes at Jul 28, 2010, 02:59 PM

                Out of curiosity, is there anything specific to Resources that you think would make this task more difficult than say, Snippets/Chunks/Plugins?
                Yes; Resources have TVs which load via AJAX, plus the code for loading an RTE is a bit different, and you’ll have to know what to do when TinyMCE is installed as well.


                Ok, I see. Definitely sounds a bit more complex than I had anticipated. In the meantime, there’s always It’s All Text! https://addons.mozilla.org/en-US/firefox/addon/4125/
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 7557
                  • 61 Posts
                  Hi!
                  I think that maybe the bug. Code mirror use for editing elements. When I create a new TV image (or file) variable in the FireFox (v.3.6.8), Code Mirror inserts a new line on default value field after saving. This produce lost of file browsers, as well as the tab title when editing resource (see photo). When only editing good TV variable without newline in default field this problem does not occur. In IE8 this does not happen. The same bug can be done without richtext editor if you type new line (enter) in default value field.
                  Thanks.
                    • 4971
                    • 964 Posts
                    Just an FYI

                    if you install CodeMirror, very nice by the way,
                    it disables "Its all text" in FF...

                    would be nice to have both working, CodeMirror for
                    minor edits in the textareas and "Its all text" to go
                    out to our editor of choice...

                    Just being greedy!
                      Website: www.mercologia.com
                      MODX Revo Tutorials:  www.modxperience.com

                      MODX Professional Partner
                      • 23491 ☆ A M B ☆
                      • 1,056 Posts
                      Quote from: dj13 at Aug 08, 2010, 05:18 AM

                      Hi!
                      I think that maybe the bug. Code mirror use for editing elements. When I create a new TV image (or file) variable in the FireFox (v.3.6.8), Code Mirror inserts a new line on default value field after saving. This produce lost of file browsers, as well as the tab title when editing resource (see photo). When only editing good TV variable without newline in default field this problem does not occur. In IE8 this does not happen. The same bug can be done without richtext editor if you type new line (enter) in default value field.
                      Thanks.


                      @dj13, I too can confirm this issue using CodeMirror to edit Default TV values. It kept inserting a new line for me as well, so for now my current solution is to disable the "OnTVFormPrerender" system event for the CodeMirror plugin till this can be fixed.
                        Mike Reid - www.pixelchutes.com
                        MODx Ambassador / Contributor
                        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                        ________________________________
                        Where every pixel matters.