From 102b5e03d41e76343deb4e70736a07aaec245508 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 15 Nov 2017 02:50:53 +0300 Subject: [PATCH] superfast cm.isBlank() instead of !cm.getValue().trim() --- edit/codemirror-default.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/edit/codemirror-default.js b/edit/codemirror-default.js index 5d38a293..e642ca3e 100644 --- a/edit/codemirror-default.js +++ b/edit/codemirror-default.js @@ -111,4 +111,16 @@ this.setOption('mode', MODE[preprocessor] || 'css'); CodeMirror.autoLoadMode(this, MODE[preprocessor] || 'css'); }); + + CodeMirror.defineExtension('isBlank', function () { + // superfast checking as it runs only until the first non-blank line + let isBlank = true; + this.doc.eachLine(line => { + if (line.text && line.text.trim()) { + isBlank = false; + return true; + } + }); + return isBlank; + }); })();