From f5b95c5d3692169b48daff3c6f3538f53dd62380 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 28 Mar 2017 17:16:32 +0800 Subject: Move updateStatusBar method into editor class --- public/js/lib/editor/config.js | 5 +++++ public/js/lib/editor/index.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 public/js/lib/editor/config.js (limited to 'public/js/lib') diff --git a/public/js/lib/editor/config.js b/public/js/lib/editor/config.js new file mode 100644 index 00000000..9508b847 --- /dev/null +++ b/public/js/lib/editor/config.js @@ -0,0 +1,5 @@ +let config = { + docmaxlength: null +} + +export default config diff --git a/public/js/lib/editor/index.js b/public/js/lib/editor/index.js index dead0c40..c807a17f 100644 --- a/public/js/lib/editor/index.js +++ b/public/js/lib/editor/index.js @@ -1,4 +1,5 @@ import * as utils from './utils' +import config from './config' /* config section */ const isMac = CodeMirror.keyMap.default === CodeMirror.keyMap.macDefault @@ -167,6 +168,28 @@ export default class Editor { } } + updateStatusBar () { + if (!this.statusBar) return + + var cursor = this.editor.getCursor() + var cursorText = 'Line ' + (cursor.line + 1) + ', Columns ' + (cursor.ch + 1) + this.statusCursor.text(cursorText) + var fileText = ' — ' + editor.lineCount() + ' Lines' + this.statusFile.text(fileText) + var docLength = editor.getValue().length + this.statusLength.text('Length ' + docLength) + if (docLength > (config.docmaxlength * 0.95)) { + this.statusLength.css('color', 'red') + this.statusLength.attr('title', 'Your almost reach note max length limit.') + } else if (docLength > (config.docmaxlength * 0.8)) { + this.statusLength.css('color', 'orange') + this.statusLength.attr('title', 'You nearly fill the note, consider to make more pieces.') + } else { + this.statusLength.css('color', 'white') + this.statusLength.attr('title', 'You could write up to ' + config.docmaxlength + ' characters in this note.') + } + } + setIndent () { var cookieIndentType = Cookies.get('indent_type') var cookieTabSize = parseInt(Cookies.get('tab_size')) -- cgit v1.2.3