Add characters count to status bar.

pull/204/head
Vladislav Bogomolov 9 years ago
parent 5f3a67dae2
commit 6c61b1a4aa

@ -171,7 +171,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
} }
/* The fake, visible scrollbars. Used to force redraw during scrolling /* The fake, visible scrollbars. Used to force redraw during scrolling
before actuall scrolling happens, thus preventing shaking and before actual scrolling happens, thus preventing shaking and
flickering artifacts. */ flickering artifacts. */
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
position: absolute; position: absolute;
@ -551,6 +551,10 @@ span.CodeMirror-selectedtext { background: none; }
content: 'words: ' content: 'words: '
} }
.editor-statusbar .characters:before {
content: 'characters: '
}
.editor-preview { .editor-preview {
padding: 10px; padding: 10px;
position: absolute; position: absolute;

File diff suppressed because one or more lines are too long

@ -7,7 +7,7 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SimpleMDE = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SimpleMDE = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){ (function (global){
; Typo = global.Typo = require("D:\\My Web Sites\\simplemde-markdown-editor\\node_modules\\codemirror-spell-checker\\src\\js\\typo.js"); ; Typo = global.Typo = require("/Users/vladson/projects/simplemde-markdown-editor/node_modules/codemirror-spell-checker/src/js/typo.js");
CodeMirror = global.CodeMirror = require("codemirror"); CodeMirror = global.CodeMirror = require("codemirror");
; var __browserify_shim_require__=require;(function browserifyShim(module, define, require) { ; var __browserify_shim_require__=require;(function browserifyShim(module, define, require) {
// Initialize data globally to reduce memory consumption // Initialize data globally to reduce memory consumption
@ -105,7 +105,7 @@ if(!String.prototype.includes) {
}).call(global, module, undefined, undefined); }).call(global, module, undefined, undefined);
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"D:\\My Web Sites\\simplemde-markdown-editor\\node_modules\\codemirror-spell-checker\\src\\js\\typo.js":2,"codemirror":6}],2:[function(require,module,exports){ },{"/Users/vladson/projects/simplemde-markdown-editor/node_modules/codemirror-spell-checker/src/js/typo.js":2,"codemirror":6}],2:[function(require,module,exports){
(function (global){ (function (global){
; var __browserify_shim_require__=require;(function browserifyShim(module, exports, require, define, browserify_shim__define__module__export__) { ; var __browserify_shim_require__=require;(function browserifyShim(module, exports, require, define, browserify_shim__define__module__export__) {
'use strict'; 'use strict';
@ -1078,7 +1078,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
return define([], mod); return define([], mod);
else // Plain browser env else // Plain browser env
this.CodeMirror = mod(); (this || window).CodeMirror = mod();
})(function() { })(function() {
"use strict"; "use strict";
@ -2159,10 +2159,6 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); } if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
} }
function isReadOnly(cm) {
return cm.options.readOnly || cm.doc.cantEdit;
}
// This will be set to an array of strings when copying, so that, // This will be set to an array of strings when copying, so that,
// when pasting, we know what kind of selections the copied text // when pasting, we know what kind of selections the copied text
// was made out of. // was made out of.
@ -2217,7 +2213,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
var pasted = e.clipboardData && e.clipboardData.getData("text/plain"); var pasted = e.clipboardData && e.clipboardData.getData("text/plain");
if (pasted) { if (pasted) {
e.preventDefault(); e.preventDefault();
if (!isReadOnly(cm) && !cm.options.disableInput) if (!cm.isReadOnly() && !cm.options.disableInput)
runInOp(cm, function() { applyTextInput(cm, pasted, 0, null, "paste"); }); runInOp(cm, function() { applyTextInput(cm, pasted, 0, null, "paste"); });
return true; return true;
} }
@ -2488,7 +2484,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
// in which case reading its value would be expensive. // in which case reading its value would be expensive.
if (this.contextMenuPending || !cm.state.focused || if (this.contextMenuPending || !cm.state.focused ||
(hasSelection(input) && !prevInput && !this.composing) || (hasSelection(input) && !prevInput && !this.composing) ||
isReadOnly(cm) || cm.options.disableInput || cm.state.keySeq) cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
return false; return false;
var text = input.value; var text = input.value;
@ -2677,7 +2673,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
on(div, "input", function() { on(div, "input", function() {
if (input.composing) return; if (input.composing) return;
if (isReadOnly(cm) || !input.pollContent()) if (cm.isReadOnly() || !input.pollContent())
runInOp(input.cm, function() {regChange(cm);}); runInOp(input.cm, function() {regChange(cm);});
}); });
@ -2757,8 +2753,13 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
try { var rng = range(start.node, start.offset, end.offset, end.node); } try { var rng = range(start.node, start.offset, end.offset, end.node); }
catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
if (rng) { if (rng) {
sel.removeAllRanges(); if (!gecko && this.cm.state.focused) {
sel.addRange(rng); sel.collapse(start.node, start.offset);
if (!rng.collapsed) sel.addRange(rng);
} else {
sel.removeAllRanges();
sel.addRange(rng);
}
if (old && sel.anchorNode == null) sel.addRange(old); if (old && sel.anchorNode == null) sel.addRange(old);
else if (gecko) this.startGracePeriod(); else if (gecko) this.startGracePeriod();
} }
@ -2902,7 +2903,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
this.div.focus(); this.div.focus();
}, },
applyComposition: function(composing) { applyComposition: function(composing) {
if (isReadOnly(this.cm)) if (this.cm.isReadOnly())
operation(this.cm, regChange)(this.cm) operation(this.cm, regChange)(this.cm)
else if (composing.data && composing.data != composing.startData) else if (composing.data && composing.data != composing.startData)
operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel); operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel);
@ -2914,7 +2915,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
onKeyPress: function(e) { onKeyPress: function(e) {
e.preventDefault(); e.preventDefault();
if (!isReadOnly(this.cm)) if (!this.cm.isReadOnly())
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
}, },
@ -4679,7 +4680,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
} }
var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained; var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained;
if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
type == "single" && (contained = sel.contains(start)) > -1 && type == "single" && (contained = sel.contains(start)) > -1 &&
(cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) && (cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) &&
(cmp(contained.to(), start) > 0 || start.xRel < 0)) (cmp(contained.to(), start) > 0 || start.xRel < 0))
@ -4903,7 +4904,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
e_preventDefault(e); e_preventDefault(e);
if (ie) lastDrop = +new Date; if (ie) lastDrop = +new Date;
var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files; var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
if (!pos || isReadOnly(cm)) return; if (!pos || cm.isReadOnly()) return;
// Might be a file drop, in which case we simply extract the text // Might be a file drop, in which case we simply extract the text
// and insert it. // and insert it.
if (files && files.length && window.FileReader && window.File) { if (files && files.length && window.FileReader && window.File) {
@ -5142,7 +5143,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
cm.display.input.ensurePolled(); cm.display.input.ensurePolled();
var prevShift = cm.display.shift, done = false; var prevShift = cm.display.shift, done = false;
try { try {
if (isReadOnly(cm)) cm.state.suppressEdits = true; if (cm.isReadOnly()) cm.state.suppressEdits = true;
if (dropShift) cm.display.shift = false; if (dropShift) cm.display.shift = false;
done = bound(cm) != Pass; done = bound(cm) != Pass;
} finally { } finally {
@ -6303,6 +6304,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
signal(this, "overwriteToggle", this, this.state.overwrite); signal(this, "overwriteToggle", this, this.state.overwrite);
}, },
hasFocus: function() { return this.display.input.getField() == activeElt(); }, hasFocus: function() { return this.display.input.getField() == activeElt(); },
isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit); },
scrollTo: methodOp(function(x, y) { scrollTo: methodOp(function(x, y) {
if (x != null || y != null) resolveScrollToPos(this); if (x != null || y != null) resolveScrollToPos(this);
@ -14074,6 +14076,11 @@ SimpleMDE.prototype.createStatusbar = function(status) {
cm.on("update", function() { cm.on("update", function() {
el.innerHTML = wordCount(cm.getValue()); el.innerHTML = wordCount(cm.getValue());
}); });
} else if(name == "characters") {
el.innerHTML = "0";
cm.on("update", function() {
el.innerHTML = cm.getValue().length;
});
} else if(name === "lines") { } else if(name === "lines") {
el.innerHTML = "0"; el.innerHTML = "0";
cm.on("update", function() { cm.on("update", function() {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -210,6 +210,10 @@
content: 'words: ' content: 'words: '
} }
.editor-statusbar .characters:before {
content: 'characters: '
}
.editor-preview { .editor-preview {
padding: 10px; padding: 10px;
position: absolute; position: absolute;

@ -1271,6 +1271,11 @@ SimpleMDE.prototype.createStatusbar = function(status) {
cm.on("update", function() { cm.on("update", function() {
el.innerHTML = wordCount(cm.getValue()); el.innerHTML = wordCount(cm.getValue());
}); });
} else if(name == "characters") {
el.innerHTML = "0";
cm.on("update", function() {
el.innerHTML = cm.getValue().length;
});
} else if(name === "lines") { } else if(name === "lines") {
el.innerHTML = "0"; el.innerHTML = "0";
cm.on("update", function() { cm.on("update", function() {

Loading…
Cancel
Save