9ad12abef8b90e7454d08765187eeb90.js 6.4 KB

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