statusbar.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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));
  14. editor.on("changeStatus", function() {
  15. statusUpdate.schedule(100);
  16. });
  17. editor.on("changeSelection", function() {
  18. statusUpdate.schedule(100);
  19. });
  20. };
  21. (function(){
  22. this.updateStatus = function(editor) {
  23. var status = [];
  24. function add(str, separator) {
  25. str && status.push(str, separator || "|");
  26. }
  27. add(editor.keyBinding.getStatusText(editor));
  28. if (editor.commands.recording)
  29. add("REC");
  30. var c = editor.selection.lead;
  31. add(c.row + ":" + c.column, " ");
  32. if (!editor.selection.isEmpty()) {
  33. var r = editor.getSelectionRange();
  34. add("(" + (r.end.row - r.start.row) + ":" +(r.end.column - r.start.column) + ")");
  35. }
  36. status.pop();
  37. this.element.textContent = status.join("");
  38. };
  39. }).call(StatusBar.prototype);
  40. exports.StatusBar = StatusBar;
  41. });