From eebf3dae9558f7e4282427e9eb8bae97c2fda7f7 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 15 May 2013 17:32:28 +0100 Subject: [PATCH] CodeMirror updates --- plugins/tiddlywiki/codemirror/codemirroreditor.js | 14 +++++++++----- plugins/tiddlywiki/codemirror/styles.tid | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 plugins/tiddlywiki/codemirror/styles.tid diff --git a/plugins/tiddlywiki/codemirror/codemirroreditor.js b/plugins/tiddlywiki/codemirror/codemirroreditor.js index 769c8c6c0..7b88ddec5 100644 --- a/plugins/tiddlywiki/codemirror/codemirroreditor.js +++ b/plugins/tiddlywiki/codemirror/codemirroreditor.js @@ -83,15 +83,19 @@ CodeMirrorEditor.prototype.render = function() { this.editWidget.attributes = { "class": "tw-edit-CodeMirrorEditor" }; - this.editWidget.children = this.editWidget.renderer.renderTree.createRenderers(this.editWidget.renderer.renderContext,[node]); + this.editWidget.children = this.editWidget.renderer.renderTree.createRenderers(this.editWidget.renderer,[node]); }; CodeMirrorEditor.prototype.postRenderInDom = function() { if(this.type === "textarea") { - CodeMirror.fromTextArea(this.editWidget.children[0].domNode,{ - lineWrapping: true, - lineNumbers: true - }); + var self = this; + // HACK: We use the timeout because postRenderInDom is called before the dom nodes have been added to the document + window.setTimeout(function() { + self.codemirrorInstance = CodeMirror.fromTextArea(self.editWidget.children[0].domNode,{ + lineWrapping: true, + lineNumbers: true + }); + },1); } }; diff --git a/plugins/tiddlywiki/codemirror/styles.tid b/plugins/tiddlywiki/codemirror/styles.tid new file mode 100644 index 000000000..406492539 --- /dev/null +++ b/plugins/tiddlywiki/codemirror/styles.tid @@ -0,0 +1,13 @@ +title: $:/plugins/tiddlywiki/codemirror/styles +tags: [[$:/tags/stylesheet]] + +/* Make the editor resize to fit its content */ + +.CodeMirror { + height: auto; +} + +.CodeMirror-scroll { + overflow-x: auto; + overflow-y: hidden; +}