statusbar.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. define(function(require, exports, module) {
  2. "use strict";
  3. /** simple statusbar **/
  4. var dom = require("ace/lib/dom");
  5. var lang = require("ace/lib/lang");
  6. var StatusBar = function(editor, parentNode) {
  7. this.element = dom.createElement("div");
  8. this.element.className = "ace_status-indicator";
  9. this.element.style.cssText = "display: inline-block;";
  10. parentNode.appendChild(this.element);
  11. var statusUpdate = lang.delayedCall(function(){
  12. this.updateStatus(editor)
  13. }.bind(this)).schedule.bind(null, 100);
  14. editor.on("changeStatus", statusUpdate);
  15. editor.on("changeSelection", statusUpdate);
  16. editor.on("keyboardActivity", statusUpdate);
  17. };
  18. (function(){
  19. this.updateStatus = function(editor) {
  20. var status = [];
  21. function add(str, separator) {
  22. str && status.push(str, separator || "|");
  23. }
  24. add(editor.keyBinding.getStatusText(editor));
  25. if (editor.commands.recording)
  26. add("REC");
  27. var sel = editor.selection;
  28. var c = sel.lead;
  29. if (!sel.isEmpty()) {
  30. var r = editor.getSelectionRange();
  31. add("(" + (r.end.row - r.start.row) + ":" +(r.end.column - r.start.column) + ")", " ");
  32. }
  33. add(c.row + ":" + c.column, " ");
  34. if (sel.rangeCount)
  35. add("[" + sel.rangeCount + "]", " ");
  36. status.pop();
  37. this.element.textContent = status.join("");
  38. };
  39. }).call(StatusBar.prototype);
  40. exports.StatusBar = StatusBar;
  41. });