statusbar.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if (editor.$vimModeHandler)
  28. add(editor.$vimModeHandler.getStatusText());
  29. else if (editor.commands.recording)
  30. add("REC");
  31. var c = editor.selection.lead;
  32. add(c.row + ":" + c.column, " ");
  33. if (!editor.selection.isEmpty()) {
  34. var r = editor.getSelectionRange();
  35. add("(" + (r.end.row - r.start.row) + ":" +(r.end.column - r.start.column) + ")");
  36. }
  37. status.pop();
  38. this.element.textContent = status.join("");
  39. };
  40. }).call(StatusBar.prototype);
  41. exports.StatusBar = StatusBar;
  42. });