a8f124f2e0e0523eb45659ef81ec2a8b.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. ace.define("ace/split",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/editor","ace/virtual_renderer","ace/edit_session"], function(require, exports, module){"use strict";
  2. var oop = require("./lib/oop");
  3. var lang = require("./lib/lang");
  4. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  5. var Editor = require("./editor").Editor;
  6. var Renderer = require("./virtual_renderer").VirtualRenderer;
  7. var EditSession = require("./edit_session").EditSession;
  8. var Split;
  9. Split = function (container, theme, splits) {
  10. this.BELOW = 1;
  11. this.BESIDE = 0;
  12. this.$container = container;
  13. this.$theme = theme;
  14. this.$splits = 0;
  15. this.$editorCSS = "";
  16. this.$editors = [];
  17. this.$orientation = this.BESIDE;
  18. this.setSplits(splits || 1);
  19. this.$cEditor = this.$editors[0];
  20. this.on("focus", function (editor) {
  21. this.$cEditor = editor;
  22. }.bind(this));
  23. };
  24. (function () {
  25. oop.implement(this, EventEmitter);
  26. this.$createEditor = function () {
  27. var el = document.createElement("div");
  28. el.className = this.$editorCSS;
  29. el.style.cssText = "position: absolute; top:0px; bottom:0px";
  30. this.$container.appendChild(el);
  31. var editor = new Editor(new Renderer(el, this.$theme));
  32. editor.on("focus", function () {
  33. this._emit("focus", editor);
  34. }.bind(this));
  35. this.$editors.push(editor);
  36. editor.setFontSize(this.$fontSize);
  37. return editor;
  38. };
  39. this.setSplits = function (splits) {
  40. var editor;
  41. if (splits < 1) {
  42. throw "The number of splits have to be > 0!";
  43. }
  44. if (splits == this.$splits) {
  45. return;
  46. }
  47. else if (splits > this.$splits) {
  48. while (this.$splits < this.$editors.length && this.$splits < splits) {
  49. editor = this.$editors[this.$splits];
  50. this.$container.appendChild(editor.container);
  51. editor.setFontSize(this.$fontSize);
  52. this.$splits++;
  53. }
  54. while (this.$splits < splits) {
  55. this.$createEditor();
  56. this.$splits++;
  57. }
  58. }
  59. else {
  60. while (this.$splits > splits) {
  61. editor = this.$editors[this.$splits - 1];
  62. this.$container.removeChild(editor.container);
  63. this.$splits--;
  64. }
  65. }
  66. this.resize();
  67. };
  68. this.getSplits = function () {
  69. return this.$splits;
  70. };
  71. this.getEditor = function (idx) {
  72. return this.$editors[idx];
  73. };
  74. this.getCurrentEditor = function () {
  75. return this.$cEditor;
  76. };
  77. this.focus = function () {
  78. this.$cEditor.focus();
  79. };
  80. this.blur = function () {
  81. this.$cEditor.blur();
  82. };
  83. this.setTheme = function (theme) {
  84. this.$editors.forEach(function (editor) {
  85. editor.setTheme(theme);
  86. });
  87. };
  88. this.setKeyboardHandler = function (keybinding) {
  89. this.$editors.forEach(function (editor) {
  90. editor.setKeyboardHandler(keybinding);
  91. });
  92. };
  93. this.forEach = function (callback, scope) {
  94. this.$editors.forEach(callback, scope);
  95. };
  96. this.$fontSize = "";
  97. this.setFontSize = function (size) {
  98. this.$fontSize = size;
  99. this.forEach(function (editor) {
  100. editor.setFontSize(size);
  101. });
  102. };
  103. this.$cloneSession = function (session) {
  104. var s = new EditSession(session.getDocument(), session.getMode());
  105. var undoManager = session.getUndoManager();
  106. s.setUndoManager(undoManager);
  107. s.setTabSize(session.getTabSize());
  108. s.setUseSoftTabs(session.getUseSoftTabs());
  109. s.setOverwrite(session.getOverwrite());
  110. s.setBreakpoints(session.getBreakpoints());
  111. s.setUseWrapMode(session.getUseWrapMode());
  112. s.setUseWorker(session.getUseWorker());
  113. s.setWrapLimitRange(session.$wrapLimitRange.min, session.$wrapLimitRange.max);
  114. s.$foldData = session.$cloneFoldData();
  115. return s;
  116. };
  117. this.setSession = function (session, idx) {
  118. var editor;
  119. if (idx == null) {
  120. editor = this.$cEditor;
  121. }
  122. else {
  123. editor = this.$editors[idx];
  124. }
  125. var isUsed = this.$editors.some(function (editor) {
  126. return editor.session === session;
  127. });
  128. if (isUsed) {
  129. session = this.$cloneSession(session);
  130. }
  131. editor.setSession(session);
  132. return session;
  133. };
  134. this.getOrientation = function () {
  135. return this.$orientation;
  136. };
  137. this.setOrientation = function (orientation) {
  138. if (this.$orientation == orientation) {
  139. return;
  140. }
  141. this.$orientation = orientation;
  142. this.resize();
  143. };
  144. this.resize = function () {
  145. var width = this.$container.clientWidth;
  146. var height = this.$container.clientHeight;
  147. var editor;
  148. if (this.$orientation == this.BESIDE) {
  149. var editorWidth = width / this.$splits;
  150. for (var i = 0; i < this.$splits; i++) {
  151. editor = this.$editors[i];
  152. editor.container.style.width = editorWidth + "px";
  153. editor.container.style.top = "0px";
  154. editor.container.style.left = i * editorWidth + "px";
  155. editor.container.style.height = height + "px";
  156. editor.resize();
  157. }
  158. }
  159. else {
  160. var editorHeight = height / this.$splits;
  161. for (var i = 0; i < this.$splits; i++) {
  162. editor = this.$editors[i];
  163. editor.container.style.width = width + "px";
  164. editor.container.style.top = i * editorHeight + "px";
  165. editor.container.style.left = "0px";
  166. editor.container.style.height = editorHeight + "px";
  167. editor.resize();
  168. }
  169. }
  170. };
  171. }).call(Split.prototype);
  172. exports.Split = Split;
  173. });
  174. ace.define("ace/ext/split",["require","exports","module","ace/split"], function(require, exports, module){"use strict";
  175. module.exports = require("../split");
  176. }); (function() {
  177. ace.require(["ace/ext/split"], function(m) {
  178. if (typeof module == "object" && typeof exports == "object" && module) {
  179. module.exports = m;
  180. }
  181. });
  182. })();