annotate rhodecode/public/js/codemirror.js @ 2861:f034e6a13a5e beta

updated codemirror to 2.34
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 Sep 2012 16:42:40 +0200
parents 01273e4f8d63
children 31f98c850623
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 // All functions that need access to the editor's state live inside
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 // the CodeMirror function. Below that, at the bottom of the file,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 // some utilities are defined.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 // CodeMirror is the only global var we claim
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
6 window.CodeMirror = (function() {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
7 "use strict";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
8 // This is the function that produces an editor instance. Its
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 // closure is used to store the editor state.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 function CodeMirror(place, givenOptions) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 // Determine effective options based on given values and defaults.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 var options = {}, defaults = CodeMirror.defaults;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 for (var opt in defaults)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 if (defaults.hasOwnProperty(opt))
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
17 var input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
18 input.setAttribute("wrap", "off"); input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
19 // Wraps and hides input textarea
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
20 var inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
21 // The empty scrollbar content, used solely for managing the scrollbar thumb.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
22 var scrollbarInner = elt("div", null, "CodeMirror-scrollbar-inner");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
23 // The vertical scrollbar. Horizontal scrolling is handled by the scroller itself.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
24 var scrollbar = elt("div", [scrollbarInner], "CodeMirror-scrollbar");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
25 // DIVs containing the selection and the actual code
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
26 var lineDiv = elt("div"), selectionDiv = elt("div", null, null, "position: relative; z-index: -1");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
27 // Blinky cursor, and element used to ensure cursor fits at the end of a line
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
28 var cursor = elt("pre", "\u00a0", "CodeMirror-cursor"), widthForcer = elt("pre", "\u00a0", "CodeMirror-cursor", "visibility: hidden");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
29 // Used to measure text size
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
30 var measure = elt("div", null, null, "position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden;");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
31 var lineSpace = elt("div", [measure, cursor, widthForcer, selectionDiv, lineDiv], null, "position: relative; z-index: 0");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
32 var gutterText = elt("div", null, "CodeMirror-gutter-text"), gutter = elt("div", [gutterText], "CodeMirror-gutter");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
33 // Moved around its parent to cover visible view
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
34 var mover = elt("div", [gutter, elt("div", [lineSpace], "CodeMirror-lines")], null, "position: relative");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
35 // Set to the height of the text, causes scrolling
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
36 var sizer = elt("div", [mover], null, "position: relative");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
37 // Provides scrolling
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
38 var scroller = elt("div", [sizer], "CodeMirror-scroll");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
39 scroller.setAttribute("tabIndex", "-1");
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
40 // The element in which the editor lives.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
41 var wrapper = elt("div", [inputDiv, scrollbar, scroller], "CodeMirror" + (options.lineWrapping ? " CodeMirror-wrap" : ""));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
43
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
44 themeChanged(); keyMapChanged();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
45 // Needed to hide big blue blinking cursor on Mobile Safari
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
46 if (ios) input.style.width = "0px";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
47 if (!webkit) scroller.draggable = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
48 lineSpace.style.outline = "none";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
49 if (options.tabindex != null) input.tabIndex = options.tabindex;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
50 if (options.autofocus) focusInput();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
52 // Needed to handle Tab key in KHTML
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
53 if (khtml) inputDiv.style.height = "1px", inputDiv.style.position = "absolute";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
54
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
55 // Check for OS X >= 10.7. This has transparent scrollbars, so the
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
56 // overlaying of one scrollbar with another won't work. This is a
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
57 // temporary hack to simply turn off the overlay scrollbar. See
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
58 // issue #727.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
59 if (mac_geLion) { scrollbar.style.zIndex = -2; scrollbar.style.visibility = "hidden"; }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
60 // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
61 else if (ie_lt8) scrollbar.style.minWidth = "18px";
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
62
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 var poll = new Delayed(), highlight = new Delayed(), blinker;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
66 // mode holds a mode API object. doc is the tree of Line objects,
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
67 // frontier is the point up to which the content has been parsed,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
68 // and history the undo history (instance of History constructor).
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
69 var mode, doc = new BranchChunk([new LeafChunk([new Line("")])]), frontier = 0, focused;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 loadMode();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 // The selection. These are always maintained to point at valid
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 // positions. Inverted is used to remember that the user is
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 // selecting bottom-to-top.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 // Selection-related flags. shiftSelecting obviously tracks
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
76 // whether the user is holding shift.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
77 var shiftSelecting, lastClick, lastDoubleClick, lastScrollTop = 0, draggingText,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
78 overwrite = false, suppressEdits = false;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 // Variables used by startOperation/endOperation to track what
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 // happened during the operation.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
81 var updateInput, userSelChange, changes, textChanged, selectionChanged,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
82 gutterDirty, callbacks;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 // Current visible range (may be bigger than the view window).
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
84 var displayOffset = 0, showingFrom = 0, showingTo = 0, lastSizeC = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
85 // bracketHighlighted is used to remember that a bracket has been
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 // marked.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
87 var bracketHighlighted;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
88 // Tracks the maximum line length so that the horizontal scrollbar
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
89 // can be kept static when scrolling.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
90 var maxLine = getLine(0), updateMaxLine = false, maxLineChanged = true;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
91 var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
92 var goalColumn = null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
94 // Initialize the content.
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 operation(function(){setValue(options.value || ""); updateInput = false;})();
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
96 var history = new History();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 // Register our event handlers.
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
99 connect(scroller, "mousedown", operation(onMouseDown));
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
100 connect(scroller, "dblclick", operation(onDoubleClick));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
101 connect(lineSpace, "selectstart", e_preventDefault);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 // Gecko browsers fire contextmenu *after* opening the menu, at
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 // which point we can't mess with it anymore. Context menu is
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 // handled in onMouseDown for Gecko.
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
105 if (!gecko) connect(scroller, "contextmenu", onContextMenu);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
106 connect(scroller, "scroll", onScrollMain);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
107 connect(scrollbar, "scroll", onScrollBar);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
108 connect(scrollbar, "mousedown", function() {if (focused) setTimeout(focusInput, 0);});
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
109 var resizeHandler = connect(window, "resize", function() {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
110 if (wrapper.parentNode) updateDisplay(true);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
111 else resizeHandler();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
112 }, true);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 connect(input, "keyup", operation(onKeyUp));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
114 connect(input, "input", fastPoll);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 connect(input, "keydown", operation(onKeyDown));
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 connect(input, "keypress", operation(onKeyPress));
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 connect(input, "focus", onFocus);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 connect(input, "blur", onBlur);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
120 function drag_(e) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
121 if (options.onDragEvent && options.onDragEvent(instance, addStop(e))) return;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
122 e_stop(e);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
123 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
124 if (options.dragDrop) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
125 connect(scroller, "dragstart", onDragStart);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
126 connect(scroller, "dragenter", drag_);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
127 connect(scroller, "dragover", drag_);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
128 connect(scroller, "drop", operation(onDrop));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
129 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
130 connect(scroller, "paste", function(){focusInput(); fastPoll();});
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
131 connect(input, "paste", fastPoll);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
132 connect(input, "cut", operation(function(){
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
133 if (!options.readOnly) replaceSelection("");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
134 }));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
135
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
136 // Needed to handle Tab key in KHTML
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
137 if (khtml) connect(sizer, "mouseup", function() {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
138 if (document.activeElement == input) input.blur();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
139 focusInput();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
140 });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
142 // IE throws unspecified error in certain cases, when
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
143 // trying to access activeElement before onload
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
144 var hasFocus; try { hasFocus = (document.activeElement == input); } catch(e) { }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
145 if (hasFocus || options.autofocus) setTimeout(onFocus, 20);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 else onBlur();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
148 function isLine(l) {return l >= 0 && l < doc.size;}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 // The instance object that we'll return. Mostly calls out to
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 // local functions in the CodeMirror function. Some do some extra
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 // range checking and/or clipping. operation is used to wrap the
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 // call so that changes it makes are tracked, and the display is
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 // updated afterwards.
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
154 var instance = wrapper.CodeMirror = {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 getValue: getValue,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 setValue: operation(setValue),
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 getSelection: getSelection,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 replaceSelection: operation(replaceSelection),
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
159 focus: function(){window.focus(); focusInput(); onFocus(); fastPoll();},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 setOption: function(option, value) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
161 var oldVal = options[option];
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 options[option] = value;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
163 if (option == "mode" || option == "indentUnit") loadMode();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
164 else if (option == "readOnly" && value == "nocursor") {onBlur(); input.blur();}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
165 else if (option == "readOnly" && !value) {resetInput(true);}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
166 else if (option == "theme") themeChanged();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
167 else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
168 else if (option == "tabSize") updateDisplay(true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
169 else if (option == "keyMap") keyMapChanged();
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
170 if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" ||
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
171 option == "theme" || option == "lineNumberFormatter") {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
172 gutterChanged();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
173 updateDisplay(true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
174 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 getOption: function(option) {return options[option];},
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
177 getMode: function() {return mode;},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 undo: operation(undo),
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179 redo: operation(redo),
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
180 indentLine: operation(function(n, dir) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
181 if (typeof dir != "string") {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
182 if (dir == null) dir = options.smartIndent ? "smart" : "prev";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
183 else dir = dir ? "add" : "subtract";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
184 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
185 if (isLine(n)) indentLine(n, dir);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
186 }),
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
187 indentSelection: operation(indentSelected),
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 historySize: function() {return {undo: history.done.length, redo: history.undone.length};},
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
189 clearHistory: function() {history = new History();},
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
190 setHistory: function(histData) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
191 history = new History();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
192 history.done = histData.done;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
193 history.undone = histData.undone;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
194 },
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
195 getHistory: function() {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
196 function cp(arr) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
197 for (var i = 0, nw = [], nwelt; i < arr.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
198 nw.push(nwelt = []);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
199 for (var j = 0, elt = arr[i]; j < elt.length; ++j) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
200 var old = [], cur = elt[j];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
201 nwelt.push({start: cur.start, added: cur.added, old: old});
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
202 for (var k = 0; k < cur.old.length; ++k) old.push(hlText(cur.old[k]));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
203 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
204 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
205 return nw;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
206 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
207 return {done: cp(history.done), undone: cp(history.undone)};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
208 },
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 matchBrackets: operation(function(){matchBrackets(true);}),
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
210 getTokenAt: operation(function(pos) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 pos = clipPos(pos);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
212 return getLine(pos.line).getTokenAt(mode, getStateBefore(pos.line), options.tabSize, pos.ch);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
213 }),
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
214 getStateAfter: function(line) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
215 line = clipLine(line == null ? doc.size - 1: line);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
216 return getStateBefore(line + 1);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
217 },
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
218 cursorCoords: function(start, mode) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 if (start == null) start = sel.inverted;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
220 return this.charCoords(start ? sel.from : sel.to, mode);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 },
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
222 charCoords: function(pos, mode) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
223 pos = clipPos(pos);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
224 if (mode == "local") return localCoords(pos, false);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
225 if (mode == "div") return localCoords(pos, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
226 return pageCoords(pos);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
227 },
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 coordsChar: function(coords) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 var off = eltOffset(lineSpace);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
230 return coordsChar(coords.x - off.left, coords.y - off.top);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 },
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
232 markText: operation(markText),
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
233 setBookmark: setBookmark,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
234 findMarksAt: findMarksAt,
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
235 setMarker: operation(addGutterMarker),
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
236 clearMarker: operation(removeGutterMarker),
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 setLineClass: operation(setLineClass),
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
238 hideLine: operation(function(h) {return setLineHidden(h, true);}),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
239 showLine: operation(function(h) {return setLineHidden(h, false);}),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
240 onDeleteLine: function(line, f) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
241 if (typeof line == "number") {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
242 if (!isLine(line)) return null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
243 line = getLine(line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
244 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
245 (line.handlers || (line.handlers = [])).push(f);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
246 return line;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
247 },
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 lineInfo: lineInfo,
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
249 getViewport: function() { return {from: showingFrom, to: showingTo};},
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
250 addWidget: function(pos, node, scroll, vert, horiz) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
251 pos = localCoords(clipPos(pos));
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
252 var top = pos.yBot, left = pos.x;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
253 node.style.position = "absolute";
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
254 sizer.appendChild(node);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
255 if (vert == "over") top = pos.y;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
256 else if (vert == "near") {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
257 var vspace = Math.max(scroller.offsetHeight, doc.height * textHeight()),
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
258 hspace = Math.max(sizer.clientWidth, lineSpace.clientWidth) - paddingLeft();
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
259 if (pos.yBot + node.offsetHeight > vspace && pos.y > node.offsetHeight)
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
260 top = pos.y - node.offsetHeight;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
261 if (left + node.offsetWidth > hspace)
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
262 left = hspace - node.offsetWidth;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
263 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
264 node.style.top = (top + paddingTop()) + "px";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
265 node.style.left = node.style.right = "";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
266 if (horiz == "right") {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
267 left = sizer.clientWidth - node.offsetWidth;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
268 node.style.right = "0px";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
269 } else {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
270 if (horiz == "left") left = 0;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
271 else if (horiz == "middle") left = (sizer.clientWidth - node.offsetWidth) / 2;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
272 node.style.left = (left + paddingLeft()) + "px";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
273 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 if (scroll)
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
275 scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
278 lineCount: function() {return doc.size;},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
279 clipPos: clipPos,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280 getCursor: function(start) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 if (start == null) start = sel.inverted;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282 return copyPos(start ? sel.from : sel.to);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
283 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284 somethingSelected: function() {return !posEq(sel.from, sel.to);},
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
285 setCursor: operation(function(line, ch, user) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
286 if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch, user);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
287 else setCursor(line, ch, user);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288 }),
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
289 setSelection: operation(function(from, to, user) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
290 (user ? setSelectionUser : setSelection)(clipPos(from), clipPos(to || from));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
291 }),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
292 getLine: function(line) {if (isLine(line)) return getLine(line).text;},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
293 getLineHandle: function(line) {if (isLine(line)) return getLine(line);},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
294 setLine: operation(function(line, text) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
295 if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: getLine(line).text.length});
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
296 }),
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
297 removeLine: operation(function(line) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
298 if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0}));
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
299 }),
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
300 replaceRange: operation(replaceRange),
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
301 getRange: function(from, to, lineSep) {return getRange(clipPos(from), clipPos(to), lineSep);},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
303 triggerOnKeyDown: operation(onKeyDown),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
304 execCommand: function(cmd) {return commands[cmd](instance);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
305 // Stuff used by commands, probably not much use to outside code.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
306 moveH: operation(moveH),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
307 deleteH: operation(deleteH),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
308 moveV: operation(moveV),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
309 toggleOverwrite: function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
310 if(overwrite){
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
311 overwrite = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
312 cursor.className = cursor.className.replace(" CodeMirror-overwrite", "");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
313 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
314 overwrite = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
315 cursor.className += " CodeMirror-overwrite";
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
316 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
317 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
318
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
319 posFromIndex: function(off) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
320 var lineNo = 0, ch;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
321 doc.iter(0, doc.size, function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
322 var sz = line.text.length + 1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
323 if (sz > off) { ch = off; return true; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
324 off -= sz;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
325 ++lineNo;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
326 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
327 return clipPos({line: lineNo, ch: ch});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
328 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
329 indexFromPos: function (coords) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
330 if (coords.line < 0 || coords.ch < 0) return 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
331 var index = coords.ch;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
332 doc.iter(0, coords.line, function (line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
333 index += line.text.length + 1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
334 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
335 return index;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
336 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
337 scrollTo: function(x, y) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
338 if (x != null) scroller.scrollLeft = x;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
339 if (y != null) scrollbar.scrollTop = scroller.scrollTop = y;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
340 updateDisplay([]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
341 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
342 getScrollInfo: function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
343 return {x: scroller.scrollLeft, y: scrollbar.scrollTop,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
344 height: scrollbar.scrollHeight, width: scroller.scrollWidth};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
345 },
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
346 setSize: function(width, height) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
347 function interpret(val) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
348 val = String(val);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
349 return /^\d+$/.test(val) ? val + "px" : val;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
350 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
351 if (width != null) wrapper.style.width = interpret(width);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
352 if (height != null) scroller.style.height = interpret(height);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
353 instance.refresh();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
354 },
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
355
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
356 operation: function(f){return operation(f)();},
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
357 compoundChange: function(f){return compoundChange(f);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
358 refresh: function(){
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
359 updateDisplay(true, null, lastScrollTop);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
360 if (scrollbar.scrollHeight > lastScrollTop)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
361 scrollbar.scrollTop = lastScrollTop;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
362 },
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
363 getInputField: function(){return input;},
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
364 getWrapperElement: function(){return wrapper;},
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
365 getScrollerElement: function(){return scroller;},
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
366 getGutterElement: function(){return gutter;}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
367 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
368
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
369 function getLine(n) { return getLineAt(doc, n); }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
370 function updateLineHeight(line, height) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
371 gutterDirty = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
372 var diff = height - line.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
373 for (var n = line; n; n = n.parent) n.height += diff;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
374 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
375
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
376 function lineContent(line, wrapAt) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
377 if (!line.styles)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
378 line.highlight(mode, line.stateAfter = getStateBefore(lineNo(line)), options.tabSize);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
379 return line.getContent(options.tabSize, wrapAt, options.lineWrapping);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
380 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
381
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
382 function setValue(code) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
383 var top = {line: 0, ch: 0};
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
384 updateLines(top, {line: doc.size - 1, ch: getLine(doc.size-1).text.length},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
385 splitLines(code), top, top);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
386 updateInput = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
387 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
388 function getValue(lineSep) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
389 var text = [];
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
390 doc.iter(0, doc.size, function(line) { text.push(line.text); });
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
391 return text.join(lineSep || "\n");
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
392 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
393
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
394 function onScrollBar(e) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
395 if (scrollbar.scrollTop != lastScrollTop) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
396 lastScrollTop = scroller.scrollTop = scrollbar.scrollTop;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
397 updateDisplay([]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
398 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
399 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
400
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
401 function onScrollMain(e) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
402 if (options.fixedGutter && gutter.style.left != scroller.scrollLeft + "px")
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
403 gutter.style.left = scroller.scrollLeft + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
404 if (scroller.scrollTop != lastScrollTop) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
405 lastScrollTop = scroller.scrollTop;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
406 if (scrollbar.scrollTop != lastScrollTop)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
407 scrollbar.scrollTop = lastScrollTop;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
408 updateDisplay([]);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
409 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
410 if (options.onScroll) options.onScroll(instance);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
411 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
412
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
413 function onMouseDown(e) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
414 setShift(e_prop(e, "shiftKey"));
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
415 // Check whether this is a click in a widget
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
416 for (var n = e_target(e); n != wrapper; n = n.parentNode)
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
417 if (n.parentNode == sizer && n != mover) return;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
418
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
419 // See if this is a click in the gutter
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
420 for (var n = e_target(e); n != wrapper; n = n.parentNode)
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
421 if (n.parentNode == gutterText) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
422 if (options.onGutterClick)
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
423 options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom, e);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
424 return e_preventDefault(e);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
425 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
426
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
427 var start = posFromMouse(e);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
428
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
429 switch (e_button(e)) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
430 case 3:
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
431 if (gecko) onContextMenu(e);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
432 return;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
433 case 2:
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
434 if (start) setCursor(start.line, start.ch, true);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
435 setTimeout(focusInput, 20);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
436 e_preventDefault(e);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
437 return;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
438 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
439 // For button 1, if it was clicked inside the editor
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
440 // (posFromMouse returning non-null), we have to adjust the
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
441 // selection.
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
442 if (!start) {if (e_target(e) == scroller) e_preventDefault(e); return;}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
443
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
444 if (!focused) onFocus();
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
445
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
446 var now = +new Date, type = "single";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
447 if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
448 type = "triple";
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
449 e_preventDefault(e);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
450 setTimeout(focusInput, 20);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
451 selectLine(start.line);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
452 } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
453 type = "double";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
454 lastDoubleClick = {time: now, pos: start};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
455 e_preventDefault(e);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
456 var word = findWordAt(start);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
457 setSelectionUser(word.from, word.to);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
458 } else { lastClick = {time: now, pos: start}; }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
459
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
460 function dragEnd(e2) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
461 if (webkit) scroller.draggable = false;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
462 draggingText = false;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
463 up(); drop();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
464 if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
465 e_preventDefault(e2);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
466 setCursor(start.line, start.ch, true);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
467 focusInput();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
468 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
469 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
470 var last = start, going;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
471 if (options.dragDrop && dragAndDrop && !options.readOnly && !posEq(sel.from, sel.to) &&
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
472 !posLess(start, sel.from) && !posLess(sel.to, start) && type == "single") {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
473 // Let the drag handler handle this.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
474 if (webkit) scroller.draggable = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
475 var up = connect(document, "mouseup", operation(dragEnd), true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
476 var drop = connect(scroller, "drop", operation(dragEnd), true);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
477 draggingText = true;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
478 // IE's approach to draggable
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
479 if (scroller.dragDrop) scroller.dragDrop();
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
480 return;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
481 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
482 e_preventDefault(e);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
483 if (type == "single") setCursor(start.line, start.ch, true);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
484
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
485 var startstart = sel.from, startend = sel.to;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
486
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
487 function doSelect(cur) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
488 if (type == "single") {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
489 setSelectionUser(start, cur);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
490 } else if (type == "double") {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
491 var word = findWordAt(cur);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
492 if (posLess(cur, startstart)) setSelectionUser(word.from, startend);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
493 else setSelectionUser(startstart, word.to);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
494 } else if (type == "triple") {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
495 if (posLess(cur, startstart)) setSelectionUser(startend, clipPos({line: cur.line, ch: 0}));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
496 else setSelectionUser(startstart, clipPos({line: cur.line + 1, ch: 0}));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
497 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
498 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
499
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
500 function extend(e) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
501 var cur = posFromMouse(e, true);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
502 if (cur && !posEq(cur, last)) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
503 if (!focused) onFocus();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
504 last = cur;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
505 doSelect(cur);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
506 updateInput = false;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
507 var visible = visibleLines();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
508 if (cur.line >= visible.to || cur.line < visible.from)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
509 going = setTimeout(operation(function(){extend(e);}), 150);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
510 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
511 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
512
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
513 function done(e) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
514 clearTimeout(going);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
515 var cur = posFromMouse(e);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
516 if (cur) doSelect(cur);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
517 e_preventDefault(e);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
518 focusInput();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
519 updateInput = true;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
520 move(); up();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
521 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
522 var move = connect(document, "mousemove", operation(function(e) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
523 clearTimeout(going);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
524 e_preventDefault(e);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
525 if (!ie && !e_button(e)) done(e);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
526 else extend(e);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
527 }), true);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
528 var up = connect(document, "mouseup", operation(done), true);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
529 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
530 function onDoubleClick(e) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
531 for (var n = e_target(e); n != wrapper; n = n.parentNode)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
532 if (n.parentNode == gutterText) return e_preventDefault(e);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
533 e_preventDefault(e);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
534 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
535 function onDrop(e) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
536 if (options.onDragEvent && options.onDragEvent(instance, addStop(e))) return;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
537 e_preventDefault(e);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
538 var pos = posFromMouse(e, true), files = e.dataTransfer.files;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
539 if (!pos || options.readOnly) return;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
540 if (files && files.length && window.FileReader && window.File) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
541 var n = files.length, text = Array(n), read = 0;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
542 var loadFile = function(file, i) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
543 var reader = new FileReader;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
544 reader.onload = function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
545 text[i] = reader.result;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
546 if (++read == n) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
547 pos = clipPos(pos);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
548 operation(function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
549 var end = replaceRange(text.join(""), pos, pos);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
550 setSelectionUser(pos, end);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
551 })();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
552 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
553 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
554 reader.readAsText(file);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
555 };
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
556 for (var i = 0; i < n; ++i) loadFile(files[i], i);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
557 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
558 // Don't do a replace if the drop happened inside of the selected text.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
559 if (draggingText && !(posLess(pos, sel.from) || posLess(sel.to, pos))) return;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
560 try {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
561 var text = e.dataTransfer.getData("Text");
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
562 if (text) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
563 compoundChange(function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
564 var curFrom = sel.from, curTo = sel.to;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
565 setSelectionUser(pos, pos);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
566 if (draggingText) replaceRange("", curFrom, curTo);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
567 replaceSelection(text);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
568 focusInput();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
569 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
570 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
571 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
572 catch(e){}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
573 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
574 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
575 function onDragStart(e) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
576 var txt = getSelection();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
577 e.dataTransfer.setData("Text", txt);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
578
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
579 // Use dummy image instead of default browsers image.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
580 if (e.dataTransfer.setDragImage)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
581 e.dataTransfer.setDragImage(elt('img'), 0, 0);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
582 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
583
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
584 function doHandleBinding(bound, dropShift) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
585 if (typeof bound == "string") {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
586 bound = commands[bound];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
587 if (!bound) return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
588 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
589 var prevShift = shiftSelecting;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
590 try {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
591 if (options.readOnly) suppressEdits = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
592 if (dropShift) shiftSelecting = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
593 bound(instance);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
594 } catch(e) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
595 if (e != Pass) throw e;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
596 return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
597 } finally {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
598 shiftSelecting = prevShift;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
599 suppressEdits = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
600 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
601 return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
602 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
603 var maybeTransition;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
604 function handleKeyBinding(e) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
605 // Handle auto keymap transitions
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
606 var startMap = getKeyMap(options.keyMap), next = startMap.auto;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
607 clearTimeout(maybeTransition);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
608 if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
609 if (getKeyMap(options.keyMap) == startMap) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
610 options.keyMap = (next.call ? next.call(null, instance) : next);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
611 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
612 }, 50);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
613
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
614 var name = keyNames[e_prop(e, "keyCode")], handled = false;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
615 var flipCtrlCmd = opera && mac;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
616 if (name == null || e.altGraphKey) return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
617 if (e_prop(e, "altKey")) name = "Alt-" + name;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
618 if (e_prop(e, flipCtrlCmd ? "metaKey" : "ctrlKey")) name = "Ctrl-" + name;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
619 if (e_prop(e, flipCtrlCmd ? "ctrlKey" : "metaKey")) name = "Cmd-" + name;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
620
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
621 var stopped = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
622 function stop() { stopped = true; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
623
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
624 if (e_prop(e, "shiftKey")) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
625 handled = lookupKey("Shift-" + name, options.extraKeys, options.keyMap,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
626 function(b) {return doHandleBinding(b, true);}, stop)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
627 || lookupKey(name, options.extraKeys, options.keyMap, function(b) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
628 if (typeof b == "string" && /^go[A-Z]/.test(b)) return doHandleBinding(b);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
629 }, stop);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
630 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
631 handled = lookupKey(name, options.extraKeys, options.keyMap, doHandleBinding, stop);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
632 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
633 if (stopped) handled = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
634 if (handled) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
635 e_preventDefault(e);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
636 restartBlink();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
637 if (ie) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
638 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
639 return handled;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
640 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
641 function handleCharBinding(e, ch) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
642 var handled = lookupKey("'" + ch + "'", options.extraKeys,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
643 options.keyMap, function(b) { return doHandleBinding(b, true); });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
644 if (handled) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
645 e_preventDefault(e);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
646 restartBlink();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
647 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
648 return handled;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
649 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
650
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
651 var lastStoppedKey = null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
652 function onKeyDown(e) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
653 if (!focused) onFocus();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
654 if (ie && e.keyCode == 27) { e.returnValue = false; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
655 if (pollingFast) { if (readInput()) pollingFast = false; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
656 if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
657 var code = e_prop(e, "keyCode");
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
658 // IE does strange things with escape.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
659 setShift(code == 16 || e_prop(e, "shiftKey"));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
660 // First give onKeyEvent option a chance to handle this.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
661 var handled = handleKeyBinding(e);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
662 if (opera) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
663 lastStoppedKey = handled ? code : null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
664 // Opera has no cut event... we try to at least catch the key combo
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
665 if (!handled && code == 88 && e_prop(e, mac ? "metaKey" : "ctrlKey"))
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
666 replaceSelection("");
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
667 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
668 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
669 function onKeyPress(e) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
670 if (pollingFast) readInput();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
671 if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
672 var keyCode = e_prop(e, "keyCode"), charCode = e_prop(e, "charCode");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
673 if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
674 if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(e)) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
675 var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
676 if (options.electricChars && mode.electricChars && options.smartIndent && !options.readOnly) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
677 if (mode.electricChars.indexOf(ch) > -1)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
678 setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 75);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
679 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
680 if (handleCharBinding(e, ch)) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
681 fastPoll();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
682 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
683 function onKeyUp(e) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
684 if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
685 if (e_prop(e, "keyCode") == 16) shiftSelecting = null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
686 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
687
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
688 function onFocus() {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
689 if (options.readOnly == "nocursor") return;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
690 if (!focused) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
691 if (options.onFocus) options.onFocus(instance);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
692 focused = true;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
693 if (scroller.className.search(/\bCodeMirror-focused\b/) == -1)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
694 scroller.className += " CodeMirror-focused";
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
695 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
696 slowPoll();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
697 restartBlink();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
698 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
699 function onBlur() {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
700 if (focused) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
701 if (options.onBlur) options.onBlur(instance);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
702 focused = false;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
703 if (bracketHighlighted)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
704 operation(function(){
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
705 if (bracketHighlighted) { bracketHighlighted(); bracketHighlighted = null; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
706 })();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
707 scroller.className = scroller.className.replace(" CodeMirror-focused", "");
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
708 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
709 clearInterval(blinker);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
710 setTimeout(function() {if (!focused) shiftSelecting = null;}, 150);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
711 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
712
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
713 // Replace the range from from to to by the strings in newText.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
714 // Afterwards, set the selection to selFrom, selTo.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
715 function updateLines(from, to, newText, selFrom, selTo) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
716 if (suppressEdits) return;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
717 var old = [];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
718 doc.iter(from.line, to.line + 1, function(line) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
719 old.push(newHL(line.text, line.markedSpans));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
720 });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
721 if (history) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
722 history.addChange(from.line, newText.length, old);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
723 while (history.done.length > options.undoDepth) history.done.shift();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
724 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
725 var lines = updateMarkedSpans(hlSpans(old[0]), hlSpans(lst(old)), from.ch, to.ch, newText);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
726 updateLinesNoUndo(from, to, lines, selFrom, selTo);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
727 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
728 function unredoHelper(from, to) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
729 if (!from.length) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
730 var set = from.pop(), out = [];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
731 for (var i = set.length - 1; i >= 0; i -= 1) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
732 var change = set[i];
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
733 var replaced = [], end = change.start + change.added;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
734 doc.iter(change.start, end, function(line) { replaced.push(newHL(line.text, line.markedSpans)); });
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
735 out.push({start: change.start, added: change.old.length, old: replaced});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
736 var pos = {line: change.start + change.old.length - 1,
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
737 ch: editEnd(hlText(lst(replaced)), hlText(lst(change.old)))};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
738 updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: getLine(end-1).text.length},
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
739 change.old, pos, pos);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
740 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
741 updateInput = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
742 to.push(out);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
743 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
744 function undo() {unredoHelper(history.done, history.undone);}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
745 function redo() {unredoHelper(history.undone, history.done);}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
746
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
747 function updateLinesNoUndo(from, to, lines, selFrom, selTo) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
748 if (suppressEdits) return;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
749 var recomputeMaxLength = false, maxLineLength = maxLine.text.length;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
750 if (!options.lineWrapping)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
751 doc.iter(from.line, to.line + 1, function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
752 if (!line.hidden && line.text.length == maxLineLength) {recomputeMaxLength = true; return true;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
753 });
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
754 if (from.line != to.line || lines.length > 1) gutterDirty = true;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
755
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
756 var nlines = to.line - from.line, firstLine = getLine(from.line), lastLine = getLine(to.line);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
757 var lastHL = lst(lines);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
758
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
759 // First adjust the line structure
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
760 if (from.ch == 0 && to.ch == 0 && hlText(lastHL) == "") {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
761 // This is a whole-line replace. Treated specially to make
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
762 // sure line objects move the way they are supposed to.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
763 var added = [], prevLine = null;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
764 for (var i = 0, e = lines.length - 1; i < e; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
765 added.push(new Line(hlText(lines[i]), hlSpans(lines[i])));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
766 lastLine.update(lastLine.text, hlSpans(lastHL));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
767 if (nlines) doc.remove(from.line, nlines, callbacks);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
768 if (added.length) doc.insert(from.line, added);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
769 } else if (firstLine == lastLine) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
770 if (lines.length == 1) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
771 firstLine.update(firstLine.text.slice(0, from.ch) + hlText(lines[0]) + firstLine.text.slice(to.ch), hlSpans(lines[0]));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
772 } else {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
773 for (var added = [], i = 1, e = lines.length - 1; i < e; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
774 added.push(new Line(hlText(lines[i]), hlSpans(lines[i])));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
775 added.push(new Line(hlText(lastHL) + firstLine.text.slice(to.ch), hlSpans(lastHL)));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
776 firstLine.update(firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
777 doc.insert(from.line + 1, added);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
778 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
779 } else if (lines.length == 1) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
780 firstLine.update(firstLine.text.slice(0, from.ch) + hlText(lines[0]) + lastLine.text.slice(to.ch), hlSpans(lines[0]));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
781 doc.remove(from.line + 1, nlines, callbacks);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
782 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
783 var added = [];
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
784 firstLine.update(firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
785 lastLine.update(hlText(lastHL) + lastLine.text.slice(to.ch), hlSpans(lastHL));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
786 for (var i = 1, e = lines.length - 1; i < e; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
787 added.push(new Line(hlText(lines[i]), hlSpans(lines[i])));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
788 if (nlines > 1) doc.remove(from.line + 1, nlines - 1, callbacks);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
789 doc.insert(from.line + 1, added);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
790 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
791 if (options.lineWrapping) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
792 var perLine = Math.max(5, scroller.clientWidth / charWidth() - 3);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
793 doc.iter(from.line, from.line + lines.length, function(line) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
794 if (line.hidden) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
795 var guess = Math.ceil(line.text.length / perLine) || 1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
796 if (guess != line.height) updateLineHeight(line, guess);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
797 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
798 } else {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
799 doc.iter(from.line, from.line + lines.length, function(line) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
800 var l = line.text;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
801 if (!line.hidden && l.length > maxLineLength) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
802 maxLine = line; maxLineLength = l.length; maxLineChanged = true;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
803 recomputeMaxLength = false;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
804 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
805 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
806 if (recomputeMaxLength) updateMaxLine = true;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
807 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
808
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
809 // Adjust frontier, schedule worker
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
810 frontier = Math.min(frontier, from.line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
811 startWorker(400);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
812
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
813 var lendiff = lines.length - nlines - 1;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
814 // Remember that these lines changed, for updating the display
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
815 changes.push({from: from.line, to: to.line + 1, diff: lendiff});
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
816 if (options.onChange) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
817 // Normalize lines to contain only strings, since that's what
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
818 // the change event handler expects
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
819 for (var i = 0; i < lines.length; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
820 if (typeof lines[i] != "string") lines[i] = lines[i].text;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
821 var changeObj = {from: from, to: to, text: lines};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
822 if (textChanged) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
823 for (var cur = textChanged; cur.next; cur = cur.next) {}
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
824 cur.next = changeObj;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
825 } else textChanged = changeObj;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
826 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
827
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
828 // Update the selection
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
829 function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;}
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
830 setSelection(clipPos(selFrom), clipPos(selTo),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
831 updateLine(sel.from.line), updateLine(sel.to.line));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
832 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
833
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
834 function needsScrollbar() {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
835 var realHeight = doc.height * textHeight() + 2 * paddingTop();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
836 return realHeight * .99 > scroller.offsetHeight ? realHeight : false;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
837 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
838
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
839 function updateVerticalScroll(scrollTop) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
840 var scrollHeight = needsScrollbar();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
841 scrollbar.style.display = scrollHeight ? "block" : "none";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
842 if (scrollHeight) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
843 scrollbarInner.style.height = sizer.style.minHeight = scrollHeight + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
844 scrollbar.style.height = scroller.clientHeight + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
845 if (scrollTop != null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
846 scrollbar.scrollTop = scroller.scrollTop = scrollTop;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
847 // 'Nudge' the scrollbar to work around a Webkit bug where,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
848 // in some situations, we'd end up with a scrollbar that
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
849 // reported its scrollTop (and looked) as expected, but
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
850 // *behaved* as if it was still in a previous state (i.e.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
851 // couldn't scroll up, even though it appeared to be at the
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
852 // bottom).
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
853 if (webkit) setTimeout(function() {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
854 if (scrollbar.scrollTop != scrollTop) return;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
855 scrollbar.scrollTop = scrollTop + (scrollTop ? -1 : 1);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
856 scrollbar.scrollTop = scrollTop;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
857 }, 0);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
858 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
859 } else {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
860 sizer.style.minHeight = "";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
861 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
862 // Position the mover div to align with the current virtual scroll position
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
863 mover.style.top = displayOffset * textHeight() + "px";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
864 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
865
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
866 function computeMaxLength() {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
867 maxLine = getLine(0); maxLineChanged = true;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
868 var maxLineLength = maxLine.text.length;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
869 doc.iter(1, doc.size, function(line) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
870 var l = line.text;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
871 if (!line.hidden && l.length > maxLineLength) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
872 maxLineLength = l.length; maxLine = line;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
873 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
874 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
875 updateMaxLine = false;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
876 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
877
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
878 function replaceRange(code, from, to) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
879 from = clipPos(from);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
880 if (!to) to = from; else to = clipPos(to);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
881 code = splitLines(code);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
882 function adjustPos(pos) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
883 if (posLess(pos, from)) return pos;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
884 if (!posLess(to, pos)) return end;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
885 var line = pos.line + code.length - (to.line - from.line) - 1;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
886 var ch = pos.ch;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
887 if (pos.line == to.line)
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
888 ch += lst(code).length - (to.ch - (to.line == from.line ? from.ch : 0));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
889 return {line: line, ch: ch};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
890 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
891 var end;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
892 replaceRange1(code, from, to, function(end1) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
893 end = end1;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
894 return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
895 });
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
896 return end;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
897 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
898 function replaceSelection(code, collapse) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
899 replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
900 if (collapse == "end") return {from: end, to: end};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
901 else if (collapse == "start") return {from: sel.from, to: sel.from};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
902 else return {from: sel.from, to: end};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
903 });
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
904 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
905 function replaceRange1(code, from, to, computeSel) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
906 var endch = code.length == 1 ? code[0].length + from.ch : lst(code).length;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
907 var newSel = computeSel({line: from.line + code.length - 1, ch: endch});
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
908 updateLines(from, to, code, newSel.from, newSel.to);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
909 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
910
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
911 function getRange(from, to, lineSep) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
912 var l1 = from.line, l2 = to.line;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
913 if (l1 == l2) return getLine(l1).text.slice(from.ch, to.ch);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
914 var code = [getLine(l1).text.slice(from.ch)];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
915 doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
916 code.push(getLine(l2).text.slice(0, to.ch));
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
917 return code.join(lineSep || "\n");
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
918 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
919 function getSelection(lineSep) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
920 return getRange(sel.from, sel.to, lineSep);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
921 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
922
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
923 function slowPoll() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
924 if (pollingFast) return;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
925 poll.set(options.pollInterval, function() {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
926 readInput();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
927 if (focused) slowPoll();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
928 });
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
929 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
930 function fastPoll() {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
931 var missed = false;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
932 pollingFast = true;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
933 function p() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
934 var changed = readInput();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
935 if (!changed && !missed) {missed = true; poll.set(60, p);}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
936 else {pollingFast = false; slowPoll();}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
937 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
938 poll.set(20, p);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
939 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
940
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
941 // Previnput is a hack to work with IME. If we reset the textarea
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
942 // on every change, that breaks IME. So we look for changes
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
943 // compared to the previous content instead. (Modern browsers have
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
944 // events that indicate IME taking place, but these are not widely
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
945 // supported or compatible enough yet to rely on.)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
946 var prevInput = "";
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
947 function readInput() {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
948 if (!focused || hasSelection(input) || options.readOnly) return false;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
949 var text = input.value;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
950 if (text == prevInput) return false;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
951 if (!nestedOperation) startOperation();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
952 shiftSelecting = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
953 var same = 0, l = Math.min(prevInput.length, text.length);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
954 while (same < l && prevInput[same] == text[same]) ++same;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
955 if (same < prevInput.length)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
956 sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
957 else if (overwrite && posEq(sel.from, sel.to))
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
958 sel.to = {line: sel.to.line, ch: Math.min(getLine(sel.to.line).text.length, sel.to.ch + (text.length - same))};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
959 replaceSelection(text.slice(same), "end");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
960 if (text.length > 1000) { input.value = prevInput = ""; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
961 else prevInput = text;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
962 if (!nestedOperation) endOperation();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
963 return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
964 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
965 function resetInput(user) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
966 if (!posEq(sel.from, sel.to)) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
967 prevInput = "";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
968 input.value = getSelection();
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
969 if (focused) selectInput(input);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
970 } else if (user) prevInput = input.value = "";
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
971 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
972
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
973 function focusInput() {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
974 if (options.readOnly != "nocursor") input.focus();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
975 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
976
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
977 function scrollCursorIntoView() {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
978 var coords = calculateCursorCoords();
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
979 scrollIntoView(coords.x, coords.y, coords.x, coords.yBot);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
980 if (!focused) return;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
981 var box = sizer.getBoundingClientRect(), doScroll = null;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
982 if (coords.y + box.top < 0) doScroll = true;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
983 else if (coords.y + box.top + textHeight() > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
984 if (doScroll != null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
985 var hidden = cursor.style.display == "none";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
986 if (hidden) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
987 cursor.style.display = "";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
988 cursor.style.left = coords.x + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
989 cursor.style.top = (coords.y - displayOffset) + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
990 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
991 cursor.scrollIntoView(doScroll);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
992 if (hidden) cursor.style.display = "none";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
993 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
994 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
995 function calculateCursorCoords() {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
996 var cursor = localCoords(sel.inverted ? sel.from : sel.to);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
997 var x = options.lineWrapping ? Math.min(cursor.x, lineSpace.offsetWidth) : cursor.x;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
998 return {x: x, y: cursor.y, yBot: cursor.yBot};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
999 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1000 function scrollIntoView(x1, y1, x2, y2) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1001 var scrollPos = calculateScrollPos(x1, y1, x2, y2);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1002 if (scrollPos.scrollLeft != null) {scroller.scrollLeft = scrollPos.scrollLeft;}
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1003 if (scrollPos.scrollTop != null) {scrollbar.scrollTop = scroller.scrollTop = scrollPos.scrollTop;}
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1004 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1005 function calculateScrollPos(x1, y1, x2, y2) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1006 var pl = paddingLeft(), pt = paddingTop();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1007 y1 += pt; y2 += pt; x1 += pl; x2 += pl;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1008 var screen = scroller.clientHeight, screentop = scrollbar.scrollTop, result = {};
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1009 var docBottom = needsScrollbar() || Infinity;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1010 var atTop = y1 < pt + 10, atBottom = y2 + pt > docBottom - 10;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1011 if (y1 < screentop) result.scrollTop = atTop ? 0 : Math.max(0, y1);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1012 else if (y2 > screentop + screen) result.scrollTop = (atBottom ? docBottom : y2) - screen;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1013
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1014 var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1015 var gutterw = options.fixedGutter ? gutter.clientWidth : 0;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1016 var atLeft = x1 < gutterw + pl + 10;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1017 if (x1 < screenleft + gutterw || atLeft) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1018 if (atLeft) x1 = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1019 result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1020 } else if (x2 > screenw + screenleft - 3) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1021 result.scrollLeft = x2 + 10 - screenw;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1022 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1023 return result;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1024 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1025
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1026 function visibleLines(scrollTop) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1027 var lh = textHeight(), top = (scrollTop != null ? scrollTop : scrollbar.scrollTop) - paddingTop();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1028 var fromHeight = Math.max(0, Math.floor(top / lh));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1029 var toHeight = Math.ceil((top + scroller.clientHeight) / lh);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1030 return {from: lineAtHeight(doc, fromHeight),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1031 to: lineAtHeight(doc, toHeight)};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1032 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1033 // Uses a set of changes plus the current scroll position to
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1034 // determine which DOM updates have to be made, and makes the
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1035 // updates.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1036 function updateDisplay(changes, suppressCallback, scrollTop) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1037 if (!scroller.clientWidth) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1038 showingFrom = showingTo = displayOffset = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1039 return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1040 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1041 // Compute the new visible window
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1042 // If scrollTop is specified, use that to determine which lines
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1043 // to render instead of the current scrollbar position.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1044 var visible = visibleLines(scrollTop);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1045 // Bail out if the visible area is already rendered and nothing changed.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1046 if (changes !== true && changes.length == 0 && visible.from > showingFrom && visible.to < showingTo) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1047 updateVerticalScroll(scrollTop);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1048 return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1049 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1050 var from = Math.max(visible.from - 100, 0), to = Math.min(doc.size, visible.to + 100);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1051 if (showingFrom < from && from - showingFrom < 20) from = showingFrom;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1052 if (showingTo > to && showingTo - to < 20) to = Math.min(doc.size, showingTo);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1053
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1054 // Create a range of theoretically intact lines, and punch holes
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1055 // in that using the change info.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1056 var intact = changes === true ? [] :
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1057 computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1058 // Clip off the parts that won't be visible
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1059 var intactLines = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1060 for (var i = 0; i < intact.length; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1061 var range = intact[i];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1062 if (range.from < from) {range.domStart += (from - range.from); range.from = from;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1063 if (range.to > to) range.to = to;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1064 if (range.from >= range.to) intact.splice(i--, 1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1065 else intactLines += range.to - range.from;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1066 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1067 if (intactLines == to - from && from == showingFrom && to == showingTo) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1068 updateVerticalScroll(scrollTop);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1069 return;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1070 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1071 intact.sort(function(a, b) {return a.domStart - b.domStart;});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1072
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1073 var th = textHeight(), gutterDisplay = gutter.style.display;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1074 lineDiv.style.display = "none";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1075 patchDisplay(from, to, intact);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1076 lineDiv.style.display = gutter.style.display = "";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1077
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1078 var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1079 // This is just a bogus formula that detects when the editor is
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1080 // resized or the font size changes.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1081 if (different) lastSizeC = scroller.clientHeight + th;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1082 if (from != showingFrom || to != showingTo && options.onViewportChange)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1083 setTimeout(function(){
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1084 if (options.onViewportChange) options.onViewportChange(instance, from, to);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1085 });
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1086 showingFrom = from; showingTo = to;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1087 displayOffset = heightAtLine(doc, from);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1088 startWorker(100);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1089
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1090 // Since this is all rather error prone, it is honoured with the
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1091 // only assertion in the whole file.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1092 if (lineDiv.childNodes.length != showingTo - showingFrom)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1093 throw new Error("BAD PATCH! " + JSON.stringify(intact) + " size=" + (showingTo - showingFrom) +
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1094 " nodes=" + lineDiv.childNodes.length);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1095
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1096 function checkHeights() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1097 var curNode = lineDiv.firstChild, heightChanged = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1098 doc.iter(showingFrom, showingTo, function(line) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1099 // Work around bizarro IE7 bug where, sometimes, our curNode
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1100 // is magically replaced with a new node in the DOM, leaving
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1101 // us with a reference to an orphan (nextSibling-less) node.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1102 if (!curNode) return;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1103 if (!line.hidden) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1104 var height = Math.round(curNode.offsetHeight / th) || 1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1105 if (line.height != height) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1106 updateLineHeight(line, height);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1107 gutterDirty = heightChanged = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1108 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1109 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1110 curNode = curNode.nextSibling;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1111 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1112 return heightChanged;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1113 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1114
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1115 if (options.lineWrapping) checkHeights();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1116
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1117 gutter.style.display = gutterDisplay;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1118 if (different || gutterDirty) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1119 // If the gutter grew in size, re-check heights. If those changed, re-draw gutter.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1120 updateGutter() && options.lineWrapping && checkHeights() && updateGutter();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1121 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1122 updateVerticalScroll(scrollTop);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1123 updateSelection();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1124 if (!suppressCallback && options.onUpdate) options.onUpdate(instance);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1125 return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1126 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1127
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1128 function computeIntact(intact, changes) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1129 for (var i = 0, l = changes.length || 0; i < l; ++i) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1130 var change = changes[i], intact2 = [], diff = change.diff || 0;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1131 for (var j = 0, l2 = intact.length; j < l2; ++j) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1132 var range = intact[j];
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1133 if (change.to <= range.from && change.diff)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1134 intact2.push({from: range.from + diff, to: range.to + diff,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1135 domStart: range.domStart});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1136 else if (change.to <= range.from || change.from >= range.to)
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1137 intact2.push(range);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1138 else {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1139 if (change.from > range.from)
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1140 intact2.push({from: range.from, to: change.from, domStart: range.domStart});
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1141 if (change.to < range.to)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1142 intact2.push({from: change.to + diff, to: range.to + diff,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1143 domStart: range.domStart + (change.to - range.from)});
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1144 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1145 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1146 intact = intact2;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1147 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1148 return intact;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1149 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1150
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1151 function patchDisplay(from, to, intact) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1152 function killNode(node) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1153 var tmp = node.nextSibling;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1154 node.parentNode.removeChild(node);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1155 return tmp;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1156 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1157 // The first pass removes the DOM nodes that aren't intact.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1158 if (!intact.length) removeChildren(lineDiv);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1159 else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1160 var domPos = 0, curNode = lineDiv.firstChild, n;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1161 for (var i = 0; i < intact.length; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1162 var cur = intact[i];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1163 while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1164 for (var j = 0, e = cur.to - cur.from; j < e; ++j) {curNode = curNode.nextSibling; domPos++;}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1165 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1166 while (curNode) curNode = killNode(curNode);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1167 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1168 // This pass fills in the lines that actually changed.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1169 var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1170 doc.iter(from, to, function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1171 if (nextIntact && nextIntact.to == j) nextIntact = intact.shift();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1172 if (!nextIntact || nextIntact.from > j) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1173 if (line.hidden) var lineElement = elt("pre");
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1174 else {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1175 var lineElement = lineContent(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1176 if (line.className) lineElement.className = line.className;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1177 // Kludge to make sure the styled element lies behind the selection (by z-index)
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1178 if (line.bgClassName) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1179 var pre = elt("pre", "\u00a0", line.bgClassName, "position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: -2");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1180 lineElement = elt("div", [pre, lineElement], null, "position: relative");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1181 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1182 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1183 lineDiv.insertBefore(lineElement, curNode);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1184 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1185 curNode = curNode.nextSibling;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1186 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1187 ++j;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1188 });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1189 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1190
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1191 function updateGutter() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1192 if (!options.gutter && !options.lineNumbers) return;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1193 var hText = mover.offsetHeight, hEditor = scroller.clientHeight;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1194 gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px";
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1195 var fragment = document.createDocumentFragment(), i = showingFrom, normalNode;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1196 doc.iter(showingFrom, Math.max(showingTo, showingFrom + 1), function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1197 if (line.hidden) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1198 fragment.appendChild(elt("pre"));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1199 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1200 var marker = line.gutterMarker;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1201 var text = options.lineNumbers ? options.lineNumberFormatter(i + options.firstLineNumber) : null;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1202 if (marker && marker.text)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1203 text = marker.text.replace("%N%", text != null ? text : "");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1204 else if (text == null)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1205 text = "\u00a0";
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1206 var markerElement = fragment.appendChild(elt("pre", null, marker && marker.style));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1207 markerElement.innerHTML = text;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1208 for (var j = 1; j < line.height; ++j) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1209 markerElement.appendChild(elt("br"));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1210 markerElement.appendChild(document.createTextNode("\u00a0"));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1211 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1212 if (!marker) normalNode = i;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1213 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1214 ++i;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1215 });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1216 gutter.style.display = "none";
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1217 removeChildrenAndAdd(gutterText, fragment);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1218 // Make sure scrolling doesn't cause number gutter size to pop
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1219 if (normalNode != null && options.lineNumbers) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1220 var node = gutterText.childNodes[normalNode - showingFrom];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1221 var minwidth = String(doc.size).length, val = eltText(node.firstChild), pad = "";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1222 while (val.length + pad.length < minwidth) pad += "\u00a0";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1223 if (pad) node.insertBefore(document.createTextNode(pad), node.firstChild);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1224 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1225 gutter.style.display = "";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1226 var resized = Math.abs((parseInt(lineSpace.style.marginLeft) || 0) - gutter.offsetWidth) > 2;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1227 lineSpace.style.marginLeft = gutter.offsetWidth + "px";
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1228 gutterDirty = false;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1229 return resized;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1230 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1231 function updateSelection() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1232 var collapsed = posEq(sel.from, sel.to);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1233 var fromPos = localCoords(sel.from, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1234 var toPos = collapsed ? fromPos : localCoords(sel.to, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1235 var headPos = sel.inverted ? fromPos : toPos, th = textHeight();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1236 var wrapOff = eltOffset(wrapper), lineOff = eltOffset(lineDiv);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1237 inputDiv.style.top = Math.max(0, Math.min(scroller.offsetHeight, headPos.y + lineOff.top - wrapOff.top)) + "px";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1238 inputDiv.style.left = Math.max(0, Math.min(scroller.offsetWidth, headPos.x + lineOff.left - wrapOff.left)) + "px";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1239 if (collapsed) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1240 cursor.style.top = headPos.y + "px";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1241 cursor.style.left = (options.lineWrapping ? Math.min(headPos.x, lineSpace.offsetWidth) : headPos.x) + "px";
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1242 cursor.style.display = "";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1243 selectionDiv.style.display = "none";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1244 } else {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1245 var sameLine = fromPos.y == toPos.y, fragment = document.createDocumentFragment();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1246 var clientWidth = lineSpace.clientWidth || lineSpace.offsetWidth;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1247 var clientHeight = lineSpace.clientHeight || lineSpace.offsetHeight;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1248 var add = function(left, top, right, height) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1249 var rstyle = quirksMode ? "width: " + (!right ? clientWidth : clientWidth - right - left) + "px"
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1250 : "right: " + right + "px";
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1251 fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1252 "px; top: " + top + "px; " + rstyle + "; height: " + height + "px"));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1253 };
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1254 if (sel.from.ch && fromPos.y >= 0) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1255 var right = sameLine ? clientWidth - toPos.x : 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1256 add(fromPos.x, fromPos.y, right, th);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1257 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1258 var middleStart = Math.max(0, fromPos.y + (sel.from.ch ? th : 0));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1259 var middleHeight = Math.min(toPos.y, clientHeight) - middleStart;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1260 if (middleHeight > 0.2 * th)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1261 add(0, middleStart, 0, middleHeight);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1262 if ((!sameLine || !sel.from.ch) && toPos.y < clientHeight - .5 * th)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1263 add(0, toPos.y, clientWidth - toPos.x, th);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1264 removeChildrenAndAdd(selectionDiv, fragment);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1265 cursor.style.display = "none";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1266 selectionDiv.style.display = "";
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1267 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1268 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1269
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1270 function setShift(val) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1271 if (val) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1272 else shiftSelecting = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1273 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1274 function setSelectionUser(from, to) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1275 var sh = shiftSelecting && clipPos(shiftSelecting);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1276 if (sh) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1277 if (posLess(sh, from)) from = sh;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1278 else if (posLess(to, sh)) to = sh;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1279 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1280 setSelection(from, to);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1281 userSelChange = true;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1282 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1283 // Update the selection. Last two args are only used by
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1284 // updateLines, since they have to be expressed in the line
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1285 // numbers before the update.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1286 function setSelection(from, to, oldFrom, oldTo) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1287 goalColumn = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1288 if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1289 if (posEq(sel.from, from) && posEq(sel.to, to)) return;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1290 if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1291
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1292 // Skip over hidden lines.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1293 if (from.line != oldFrom) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1294 var from1 = skipHidden(from, oldFrom, sel.from.ch);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1295 // If there is no non-hidden line left, force visibility on current line
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1296 if (!from1) setLineHidden(from.line, false);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1297 else from = from1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1298 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1299 if (to.line != oldTo) to = skipHidden(to, oldTo, sel.to.ch);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1300
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1301 if (posEq(from, to)) sel.inverted = false;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1302 else if (posEq(from, sel.to)) sel.inverted = false;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1303 else if (posEq(to, sel.from)) sel.inverted = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1304
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1305 if (options.autoClearEmptyLines && posEq(sel.from, sel.to)) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1306 var head = sel.inverted ? from : to;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1307 if (head.line != sel.from.line && sel.from.line < doc.size) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1308 var oldLine = getLine(sel.from.line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1309 if (/^\s+$/.test(oldLine.text))
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1310 setTimeout(operation(function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1311 if (oldLine.parent && /^\s+$/.test(oldLine.text)) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1312 var no = lineNo(oldLine);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1313 replaceRange("", {line: no, ch: 0}, {line: no, ch: oldLine.text.length});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1314 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1315 }, 10));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1316 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1317 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1318
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1319 sel.from = from; sel.to = to;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1320 selectionChanged = true;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1321 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1322 function skipHidden(pos, oldLine, oldCh) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1323 function getNonHidden(dir) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1324 var lNo = pos.line + dir, end = dir == 1 ? doc.size : -1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1325 while (lNo != end) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1326 var line = getLine(lNo);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1327 if (!line.hidden) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1328 var ch = pos.ch;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1329 if (toEnd || ch > oldCh || ch > line.text.length) ch = line.text.length;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1330 return {line: lNo, ch: ch};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1331 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1332 lNo += dir;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1333 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1334 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1335 var line = getLine(pos.line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1336 var toEnd = pos.ch == line.text.length && pos.ch != oldCh;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1337 if (!line.hidden) return pos;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1338 if (pos.line >= oldLine) return getNonHidden(1) || getNonHidden(-1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1339 else return getNonHidden(-1) || getNonHidden(1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1340 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1341 function setCursor(line, ch, user) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1342 var pos = clipPos({line: line, ch: ch || 0});
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1343 (user ? setSelectionUser : setSelection)(pos, pos);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1344 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1345
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1346 function clipLine(n) {return Math.max(0, Math.min(n, doc.size-1));}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1347 function clipPos(pos) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1348 if (pos.line < 0) return {line: 0, ch: 0};
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1349 if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc.size-1).text.length};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1350 var ch = pos.ch, linelen = getLine(pos.line).text.length;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1351 if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1352 else if (ch < 0) return {line: pos.line, ch: 0};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1353 else return pos;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1354 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1355
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1356 function findPosH(dir, unit) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1357 var end = sel.inverted ? sel.from : sel.to, line = end.line, ch = end.ch;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1358 var lineObj = getLine(line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1359 function findNextLine() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1360 for (var l = line + dir, e = dir < 0 ? -1 : doc.size; l != e; l += dir) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1361 var lo = getLine(l);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1362 if (!lo.hidden) { line = l; lineObj = lo; return true; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1363 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1364 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1365 function moveOnce(boundToLine) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1366 if (ch == (dir < 0 ? 0 : lineObj.text.length)) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1367 if (!boundToLine && findNextLine()) ch = dir < 0 ? lineObj.text.length : 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1368 else return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1369 } else ch += dir;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1370 return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1371 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1372 if (unit == "char") moveOnce();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1373 else if (unit == "column") moveOnce(true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1374 else if (unit == "word") {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1375 var sawWord = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1376 for (;;) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1377 if (dir < 0) if (!moveOnce()) break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1378 if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1379 else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1380 if (dir > 0) if (!moveOnce()) break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1381 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1382 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1383 return {line: line, ch: ch};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1384 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1385 function moveH(dir, unit) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1386 var pos = dir < 0 ? sel.from : sel.to;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1387 if (shiftSelecting || posEq(sel.from, sel.to)) pos = findPosH(dir, unit);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1388 setCursor(pos.line, pos.ch, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1389 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1390 function deleteH(dir, unit) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1391 if (!posEq(sel.from, sel.to)) replaceRange("", sel.from, sel.to);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1392 else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1393 else replaceRange("", sel.from, findPosH(dir, unit));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1394 userSelChange = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1395 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1396 function moveV(dir, unit) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1397 var dist = 0, pos = localCoords(sel.inverted ? sel.from : sel.to, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1398 if (goalColumn != null) pos.x = goalColumn;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1399 if (unit == "page") {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1400 var screen = Math.min(scroller.clientHeight, window.innerHeight || document.documentElement.clientHeight);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1401 var target = coordsChar(pos.x, pos.y + screen * dir);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1402 } else if (unit == "line") {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1403 var th = textHeight();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1404 var target = coordsChar(pos.x, pos.y + .5 * th + dir * th);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1405 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1406 if (unit == "page") scrollbar.scrollTop += localCoords(target, true).y - pos.y;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1407 setCursor(target.line, target.ch, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1408 goalColumn = pos.x;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1409 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1410
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1411 function findWordAt(pos) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1412 var line = getLine(pos.line).text;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1413 var start = pos.ch, end = pos.ch;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1414 if (line) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1415 if (pos.after === false || end == line.length) --start; else ++end;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1416 var startChar = line.charAt(start);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1417 var check = isWordChar(startChar) ? isWordChar :
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1418 /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} :
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1419 function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1420 while (start > 0 && check(line.charAt(start - 1))) --start;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1421 while (end < line.length && check(line.charAt(end))) ++end;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1422 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1423 return {from: {line: pos.line, ch: start}, to: {line: pos.line, ch: end}};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1424 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1425 function selectLine(line) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1426 setSelectionUser({line: line, ch: 0}, clipPos({line: line + 1, ch: 0}));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1427 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1428 function indentSelected(mode) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1429 if (posEq(sel.from, sel.to)) return indentLine(sel.from.line, mode);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1430 var e = sel.to.line - (sel.to.ch ? 0 : 1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1431 for (var i = sel.from.line; i <= e; ++i) indentLine(i, mode);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1432 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1433
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1434 function indentLine(n, how) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1435 if (!how) how = "add";
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1436 if (how == "smart") {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1437 if (!mode.indent) how = "prev";
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1438 else var state = getStateBefore(n);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1439 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1440
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1441 var line = getLine(n), curSpace = line.indentation(options.tabSize),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1442 curSpaceString = line.text.match(/^\s*/)[0], indentation;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1443 if (how == "smart") {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1444 indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1445 if (indentation == Pass) how = "prev";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1446 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1447 if (how == "prev") {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1448 if (n) indentation = getLine(n-1).indentation(options.tabSize);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1449 else indentation = 0;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1450 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1451 else if (how == "add") indentation = curSpace + options.indentUnit;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1452 else if (how == "subtract") indentation = curSpace - options.indentUnit;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1453 indentation = Math.max(0, indentation);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1454 var diff = indentation - curSpace;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1455
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1456 var indentString = "", pos = 0;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1457 if (options.indentWithTabs)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1458 for (var i = Math.floor(indentation / options.tabSize); i; --i) {pos += options.tabSize; indentString += "\t";}
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1459 if (pos < indentation) indentString += spaceStr(indentation - pos);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1460
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1461 if (indentString != curSpaceString)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1462 replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1463 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1464
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1465 function loadMode() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1466 mode = CodeMirror.getMode(options, options.mode);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1467 doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1468 frontier = 0;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1469 startWorker(100);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1470 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1471 function gutterChanged() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1472 var visible = options.gutter || options.lineNumbers;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1473 gutter.style.display = visible ? "" : "none";
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1474 if (visible) gutterDirty = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1475 else lineDiv.parentNode.style.marginLeft = 0;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1476 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1477 function wrappingChanged(from, to) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1478 if (options.lineWrapping) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1479 wrapper.className += " CodeMirror-wrap";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1480 var perLine = scroller.clientWidth / charWidth() - 3;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1481 doc.iter(0, doc.size, function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1482 if (line.hidden) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1483 var guess = Math.ceil(line.text.length / perLine) || 1;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1484 if (guess != 1) updateLineHeight(line, guess);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1485 });
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1486 lineSpace.style.minWidth = widthForcer.style.left = "";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1487 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1488 wrapper.className = wrapper.className.replace(" CodeMirror-wrap", "");
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1489 computeMaxLength();
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1490 doc.iter(0, doc.size, function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1491 if (line.height != 1 && !line.hidden) updateLineHeight(line, 1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1492 });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1493 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1494 changes.push({from: 0, to: doc.size});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1495 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1496 function themeChanged() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1497 scroller.className = scroller.className.replace(/\s*cm-s-\S+/g, "") +
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1498 options.theme.replace(/(^|\s)\s*/g, " cm-s-");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1499 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1500 function keyMapChanged() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1501 var style = keyMap[options.keyMap].style;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1502 wrapper.className = wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1503 (style ? " cm-keymap-" + style : "");
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1504 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1505
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1506 function TextMarker(type, style) { this.lines = []; this.type = type; if (style) this.style = style; }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1507 TextMarker.prototype.clear = operation(function() {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1508 var min = Infinity, max = -Infinity;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1509 for (var i = 0; i < this.lines.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1510 var line = this.lines[i];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1511 var span = getMarkedSpanFor(line.markedSpans, this, true);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1512 if (span.from != null || span.to != null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1513 var lineN = lineNo(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1514 min = Math.min(min, lineN); max = Math.max(max, lineN);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1515 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1516 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1517 if (min != Infinity)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1518 changes.push({from: min, to: max + 1});
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1519 this.lines.length = 0;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1520 });
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1521 TextMarker.prototype.find = function() {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1522 var from, to;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1523 for (var i = 0; i < this.lines.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1524 var line = this.lines[i];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1525 var span = getMarkedSpanFor(line.markedSpans, this);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1526 if (span.from != null || span.to != null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1527 var found = lineNo(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1528 if (span.from != null) from = {line: found, ch: span.from};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1529 if (span.to != null) to = {line: found, ch: span.to};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1530 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1531 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1532 if (this.type == "bookmark") return from;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1533 return from && {from: from, to: to};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1534 };
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1535
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1536 function markText(from, to, className, options) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1537 from = clipPos(from); to = clipPos(to);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1538 var marker = new TextMarker("range", className);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1539 if (options) for (var opt in options) if (options.hasOwnProperty(opt))
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1540 marker[opt] = options[opt];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1541 var curLine = from.line;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1542 doc.iter(curLine, to.line + 1, function(line) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1543 var span = {from: curLine == from.line ? from.ch : null,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1544 to: curLine == to.line ? to.ch : null,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1545 marker: marker};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1546 (line.markedSpans || (line.markedSpans = [])).push(span);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1547 marker.lines.push(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1548 ++curLine;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1549 });
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1550 changes.push({from: from.line, to: to.line + 1});
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1551 return marker;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1552 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1553
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1554 function setBookmark(pos) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1555 pos = clipPos(pos);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1556 var marker = new TextMarker("bookmark"), line = getLine(pos.line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1557 var span = {from: pos.ch, to: pos.ch, marker: marker};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1558 (line.markedSpans || (line.markedSpans = [])).push(span);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1559 marker.lines.push(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1560 return marker;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1561 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1562
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1563 function findMarksAt(pos) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1564 pos = clipPos(pos);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1565 var markers = [], spans = getLine(pos.line).markedSpans;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1566 if (spans) for (var i = 0; i < spans.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1567 var span = spans[i];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1568 if ((span.from == null || span.from <= pos.ch) &&
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1569 (span.to == null || span.to >= pos.ch))
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1570 markers.push(span.marker);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1571 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1572 return markers;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1573 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1574
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1575 function addGutterMarker(line, text, className) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1576 if (typeof line == "number") line = getLine(clipLine(line));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1577 line.gutterMarker = {text: text, style: className};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1578 gutterDirty = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1579 return line;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1580 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1581 function removeGutterMarker(line) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1582 if (typeof line == "number") line = getLine(clipLine(line));
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1583 line.gutterMarker = null;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1584 gutterDirty = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1585 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1586
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1587 function changeLine(handle, op) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1588 var no = handle, line = handle;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1589 if (typeof handle == "number") line = getLine(clipLine(handle));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1590 else no = lineNo(handle);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1591 if (no == null) return null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1592 if (op(line, no)) changes.push({from: no, to: no + 1});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1593 else return null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1594 return line;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1595 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1596 function setLineClass(handle, className, bgClassName) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1597 return changeLine(handle, function(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1598 if (line.className != className || line.bgClassName != bgClassName) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1599 line.className = className;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1600 line.bgClassName = bgClassName;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1601 return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1602 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1603 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1604 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1605 function setLineHidden(handle, hidden) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1606 return changeLine(handle, function(line, no) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1607 if (line.hidden != hidden) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1608 line.hidden = hidden;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1609 if (!options.lineWrapping) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1610 if (hidden && line.text.length == maxLine.text.length) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1611 updateMaxLine = true;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1612 } else if (!hidden && line.text.length > maxLine.text.length) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1613 maxLine = line; updateMaxLine = false;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1614 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1615 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1616 updateLineHeight(line, hidden ? 0 : 1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1617 var fline = sel.from.line, tline = sel.to.line;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1618 if (hidden && (fline == no || tline == no)) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1619 var from = fline == no ? skipHidden({line: fline, ch: 0}, fline, 0) : sel.from;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1620 var to = tline == no ? skipHidden({line: tline, ch: 0}, tline, 0) : sel.to;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1621 // Can't hide the last visible line, we'd have no place to put the cursor
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1622 if (!to) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1623 setSelection(from, to);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1624 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1625 return (gutterDirty = true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1626 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1627 });
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1628 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1629
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1630 function lineInfo(line) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1631 if (typeof line == "number") {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1632 if (!isLine(line)) return null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1633 var n = line;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1634 line = getLine(line);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1635 if (!line) return null;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1636 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1637 var n = lineNo(line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1638 if (n == null) return null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1639 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1640 var marker = line.gutterMarker;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1641 return {line: n, handle: line, text: line.text, markerText: marker && marker.text,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1642 markerClass: marker && marker.style, lineClass: line.className, bgClass: line.bgClassName};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1643 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1644
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1645 function measureLine(line, ch) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1646 if (ch == 0) return {top: 0, left: 0};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1647 var wbr = options.lineWrapping && ch < line.text.length &&
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1648 spanAffectsWrapping.test(line.text.slice(ch - 1, ch + 1));
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1649 var pre = lineContent(line, ch);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1650 removeChildrenAndAdd(measure, pre);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1651 var anchor = pre.anchor;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1652 var top = anchor.offsetTop, left = anchor.offsetLeft;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1653 // Older IEs report zero offsets for spans directly after a wrap
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1654 if (ie && top == 0 && left == 0) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1655 var backup = elt("span", "x");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1656 anchor.parentNode.insertBefore(backup, anchor.nextSibling);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1657 top = backup.offsetTop;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1658 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1659 return {top: top, left: left};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1660 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1661 function localCoords(pos, inLineWrap) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1662 var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1663 if (pos.ch == 0) x = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1664 else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1665 var sp = measureLine(getLine(pos.line), pos.ch);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1666 x = sp.left;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1667 if (options.lineWrapping) y += Math.max(0, sp.top);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1668 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1669 return {x: x, y: y, yBot: y + lh};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1670 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1671 // Coords must be lineSpace-local
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1672 function coordsChar(x, y) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1673 var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1674 if (heightPos < 0) return {line: 0, ch: 0};
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1675 var lineNo = lineAtHeight(doc, heightPos);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1676 if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1677 var lineObj = getLine(lineNo), text = lineObj.text;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1678 var tw = options.lineWrapping, innerOff = tw ? heightPos - heightAtLine(doc, lineNo) : 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1679 if (x <= 0 && innerOff == 0) return {line: lineNo, ch: 0};
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1680 var wrongLine = false;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1681 function getX(len) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1682 var sp = measureLine(lineObj, len);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1683 if (tw) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1684 var off = Math.round(sp.top / th);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1685 wrongLine = off != innerOff;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1686 return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1687 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1688 return sp.left;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1689 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1690 var from = 0, fromX = 0, to = text.length, toX;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1691 // Guess a suitable upper bound for our search.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1692 var estimated = Math.min(to, Math.ceil((x + innerOff * scroller.clientWidth * .9) / cw));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1693 for (;;) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1694 var estX = getX(estimated);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1695 if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1696 else {toX = estX; to = estimated; break;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1697 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1698 if (x > toX) return {line: lineNo, ch: to};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1699 // Try to guess a suitable lower bound as well.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1700 estimated = Math.floor(to * 0.8); estX = getX(estimated);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1701 if (estX < x) {from = estimated; fromX = estX;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1702 // Do a binary search between these bounds.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1703 for (;;) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1704 if (to - from <= 1) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1705 var after = x - fromX < toX - x;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1706 return {line: lineNo, ch: after ? from : to, after: after};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1707 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1708 var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1709 if (middleX > x) {to = middle; toX = middleX; if (wrongLine) toX += 1000; }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1710 else {from = middle; fromX = middleX;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1711 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1712 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1713 function pageCoords(pos) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1714 var local = localCoords(pos, true), off = eltOffset(lineSpace);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1715 return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1716 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1717
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1718 var cachedHeight, cachedHeightFor, measurePre;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1719 function textHeight() {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1720 if (measurePre == null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1721 measurePre = elt("pre");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1722 for (var i = 0; i < 49; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1723 measurePre.appendChild(document.createTextNode("x"));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1724 measurePre.appendChild(elt("br"));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1725 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1726 measurePre.appendChild(document.createTextNode("x"));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1727 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1728 var offsetHeight = lineDiv.clientHeight;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1729 if (offsetHeight == cachedHeightFor) return cachedHeight;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1730 cachedHeightFor = offsetHeight;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1731 removeChildrenAndAdd(measure, measurePre.cloneNode(true));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1732 cachedHeight = measure.firstChild.offsetHeight / 50 || 1;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1733 removeChildren(measure);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1734 return cachedHeight;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1735 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1736 var cachedWidth, cachedWidthFor = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1737 function charWidth() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1738 if (scroller.clientWidth == cachedWidthFor) return cachedWidth;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1739 cachedWidthFor = scroller.clientWidth;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1740 var anchor = elt("span", "x");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1741 var pre = elt("pre", [anchor]);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1742 removeChildrenAndAdd(measure, pre);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1743 return (cachedWidth = anchor.offsetWidth || 10);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1744 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1745 function paddingTop() {return lineSpace.offsetTop;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1746 function paddingLeft() {return lineSpace.offsetLeft;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1747
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1748 function posFromMouse(e, liberal) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1749 var offW = eltOffset(scroller, true), x, y;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1750 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1751 try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1752 // This is a mess of a heuristic to try and determine whether a
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1753 // scroll-bar was clicked or not, and to return null if one was
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1754 // (and !liberal).
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1755 if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight))
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1756 return null;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1757 var offL = eltOffset(lineSpace, true);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1758 return coordsChar(x - offL.left, y - offL.top);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1759 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1760 var detectingSelectAll;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1761 function onContextMenu(e) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1762 var pos = posFromMouse(e), scrollPos = scrollbar.scrollTop;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1763 if (!pos || opera) return; // Opera is difficult.
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1764 if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1765 operation(setCursor)(pos.line, pos.ch);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1766
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1767 var oldCSS = input.style.cssText;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1768 inputDiv.style.position = "absolute";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1769 input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1770 "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; " +
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1771 "border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1772 focusInput();
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1773 resetInput(true);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1774 // Adds "Select all" to context menu in FF
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1775 if (posEq(sel.from, sel.to)) input.value = prevInput = " ";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1776
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1777 function rehide() {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1778 inputDiv.style.position = "relative";
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1779 input.style.cssText = oldCSS;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1780 if (ie_lt9) scrollbar.scrollTop = scrollPos;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1781 slowPoll();
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1782
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1783 // Try to detect the user choosing select-all
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1784 if (input.selectionStart != null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1785 clearTimeout(detectingSelectAll);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1786 var extval = input.value = " " + (posEq(sel.from, sel.to) ? "" : input.value), i = 0;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1787 prevInput = " ";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1788 input.selectionStart = 1; input.selectionEnd = extval.length;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1789 detectingSelectAll = setTimeout(function poll(){
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1790 if (prevInput == " " && input.selectionStart == 0)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1791 operation(commands.selectAll)(instance);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1792 else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1793 else resetInput();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1794 }, 200);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1795 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1796 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1797
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1798 if (gecko) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1799 e_stop(e);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1800 var mouseup = connect(window, "mouseup", function() {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1801 mouseup();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1802 setTimeout(rehide, 20);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1803 }, true);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1804 } else {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1805 setTimeout(rehide, 50);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1806 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1807 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1808
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1809 // Cursor-blinking
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1810 function restartBlink() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1811 clearInterval(blinker);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1812 var on = true;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1813 cursor.style.visibility = "";
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1814 blinker = setInterval(function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1815 cursor.style.visibility = (on = !on) ? "" : "hidden";
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1816 }, options.cursorBlinkRate);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1817 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1818
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1819 var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1820 function matchBrackets(autoclear) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1821 var head = sel.inverted ? sel.from : sel.to, line = getLine(head.line), pos = head.ch - 1;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1822 var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1823 if (!match) return;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1824 var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1825 for (var off = pos + 1, i = 0, e = st.length; i < e; i+=2)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1826 if ((off -= st[i].length) <= 0) {var style = st[i+1]; break;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1827
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1828 var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1829 function scan(line, from, to) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1830 if (!line.text) return;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1831 var st = line.styles, pos = forward ? 0 : line.text.length - 1, cur;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1832 for (var i = forward ? 0 : st.length - 2, e = forward ? st.length : -2; i != e; i += 2*d) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1833 var text = st[i];
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1834 if (st[i+1] != style) {pos += d * text.length; continue;}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1835 for (var j = forward ? 0 : text.length - 1, te = forward ? text.length : -1; j != te; j += d, pos+=d) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1836 if (pos >= from && pos < to && re.test(cur = text.charAt(j))) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1837 var match = matching[cur];
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1838 if (match.charAt(1) == ">" == forward) stack.push(cur);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1839 else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1840 else if (!stack.length) return {pos: pos, match: true};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1841 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1842 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1843 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1844 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1845 for (var i = head.line, e = forward ? Math.min(i + 100, doc.size) : Math.max(-1, i - 100); i != e; i+=d) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1846 var line = getLine(i), first = i == head.line;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1847 var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1848 if (found) break;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1849 }
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1850 if (!found) found = {pos: null, match: false};
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1851 var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1852 var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style),
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1853 two = found.pos != null && markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1854 var clear = operation(function(){one.clear(); two && two.clear();});
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1855 if (autoclear) setTimeout(clear, 800);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1856 else bracketHighlighted = clear;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1857 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1858
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1859 // Finds the line to start with when starting a parse. Tries to
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1860 // find a line with a stateAfter, so that it can start with a
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1861 // valid state. If that fails, it returns the line with the
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1862 // smallest indentation, which tends to need the least context to
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1863 // parse correctly.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1864 function findStartLine(n) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1865 var minindent, minline;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1866 for (var search = n, lim = n - 40; search > lim; --search) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1867 if (search == 0) return 0;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1868 var line = getLine(search-1);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1869 if (line.stateAfter) return search;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1870 var indented = line.indentation(options.tabSize);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1871 if (minline == null || minindent > indented) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1872 minline = search - 1;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1873 minindent = indented;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1874 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1875 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1876 return minline;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1877 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1878 function getStateBefore(n) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1879 var pos = findStartLine(n), state = pos && getLine(pos-1).stateAfter;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1880 if (!state) state = startState(mode);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1881 else state = copyState(mode, state);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1882 doc.iter(pos, n, function(line) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1883 line.process(mode, state, options.tabSize);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1884 line.stateAfter = (pos == n - 1 || pos % 5 == 0) ? copyState(mode, state) : null;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1885 });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1886 return state;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1887 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1888 function highlightWorker() {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1889 if (frontier >= showingTo) return;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1890 var end = +new Date + options.workTime, state = copyState(mode, getStateBefore(frontier));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1891 var startFrontier = frontier;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1892 doc.iter(frontier, showingTo, function(line) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1893 if (frontier >= showingFrom) { // Visible
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1894 line.highlight(mode, state, options.tabSize);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1895 line.stateAfter = copyState(mode, state);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1896 } else {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1897 line.process(mode, state, options.tabSize);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1898 line.stateAfter = frontier % 5 == 0 ? copyState(mode, state) : null;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1899 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1900 ++frontier;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1901 if (+new Date > end) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1902 startWorker(options.workDelay);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1903 return true;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1904 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1905 });
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1906 if (showingTo > startFrontier && frontier >= showingFrom)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1907 operation(function() {changes.push({from: startFrontier, to: frontier});})();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1908 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1909 function startWorker(time) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1910 if (frontier < showingTo)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1911 highlight.set(time, highlightWorker);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1912 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1913
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1914 // Operations are used to wrap changes in such a way that each
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1915 // change won't have to update the cursor and display (which would
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1916 // be awkward, slow, and error-prone), but instead updates are
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1917 // batched and then all combined and executed at once.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1918 function startOperation() {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1919 updateInput = userSelChange = textChanged = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1920 changes = []; selectionChanged = false; callbacks = [];
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1921 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1922 function endOperation() {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1923 if (updateMaxLine) computeMaxLength();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1924 if (maxLineChanged && !options.lineWrapping) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1925 var cursorWidth = widthForcer.offsetWidth, left = measureLine(maxLine, maxLine.text.length).left;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1926 if (!ie_lt8) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1927 widthForcer.style.left = left + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1928 lineSpace.style.minWidth = (left + cursorWidth) + "px";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1929 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1930 maxLineChanged = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1931 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1932 var newScrollPos, updated;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1933 if (selectionChanged) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1934 var coords = calculateCursorCoords();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1935 newScrollPos = calculateScrollPos(coords.x, coords.y, coords.x, coords.yBot);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1936 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1937 if (changes.length || newScrollPos && newScrollPos.scrollTop != null)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1938 updated = updateDisplay(changes, true, newScrollPos && newScrollPos.scrollTop);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1939 if (!updated) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1940 if (selectionChanged) updateSelection();
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1941 if (gutterDirty) updateGutter();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1942 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1943 if (newScrollPos) scrollCursorIntoView();
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1944 if (selectionChanged) restartBlink();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1945
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
1946 if (focused && (updateInput === true || (updateInput !== false && selectionChanged)))
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1947 resetInput(userSelChange);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1948
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1949 if (selectionChanged && options.matchBrackets)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1950 setTimeout(operation(function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1951 if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;}
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1952 if (posEq(sel.from, sel.to)) matchBrackets(false);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1953 }), 20);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1954 var sc = selectionChanged, cbs = callbacks; // these can be reset by callbacks
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1955 if (textChanged && options.onChange && instance)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1956 options.onChange(instance, textChanged);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1957 if (sc && options.onCursorActivity)
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1958 options.onCursorActivity(instance);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1959 for (var i = 0; i < cbs.length; ++i) cbs[i](instance);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1960 if (updated && options.onUpdate) options.onUpdate(instance);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1961 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1962 var nestedOperation = 0;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1963 function operation(f) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1964 return function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1965 if (!nestedOperation++) startOperation();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1966 try {var result = f.apply(this, arguments);}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1967 finally {if (!--nestedOperation) endOperation();}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1968 return result;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1969 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1970 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1971
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1972 function compoundChange(f) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1973 history.startCompound();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1974 try { return f(); } finally { history.endCompound(); }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1975 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1976
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1977 for (var ext in extensions)
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1978 if (extensions.propertyIsEnumerable(ext) &&
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1979 !instance.propertyIsEnumerable(ext))
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1980 instance[ext] = extensions[ext];
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1981 return instance;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1982 } // (end of function CodeMirror)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1983
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1984 // The default configuration options.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1985 CodeMirror.defaults = {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1986 value: "",
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1987 mode: null,
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
1988 theme: "default",
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1989 indentUnit: 2,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1990 indentWithTabs: false,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1991 smartIndent: true,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1992 tabSize: 4,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1993 keyMap: "default",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1994 extraKeys: null,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1995 electricChars: true,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1996 autoClearEmptyLines: false,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1997 onKeyEvent: null,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1998 onDragEvent: null,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
1999 lineWrapping: false,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2000 lineNumbers: false,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2001 gutter: false,
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2002 fixedGutter: false,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2003 firstLineNumber: 1,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2004 readOnly: false,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2005 dragDrop: true,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2006 onChange: null,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2007 onCursorActivity: null,
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2008 onViewportChange: null,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2009 onGutterClick: null,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2010 onUpdate: null,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2011 onFocus: null, onBlur: null, onScroll: null,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2012 matchBrackets: false,
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2013 cursorBlinkRate: 530,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2014 workTime: 100,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2015 workDelay: 200,
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2016 pollInterval: 100,
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2017 undoDepth: 40,
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2018 tabindex: null,
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2019 autofocus: null,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2020 lineNumberFormatter: function(integer) { return integer; }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2021 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2022
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2023 var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2024 var mac = ios || /Mac/.test(navigator.platform);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2025 var win = /Win/.test(navigator.platform);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2026
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2027 // Known modes, by name and by MIME
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2028 var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2029 CodeMirror.defineMode = function(name, mode) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2030 if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2031 if (arguments.length > 2) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2032 mode.dependencies = [];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2033 for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2034 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2035 modes[name] = mode;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2036 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2037 CodeMirror.defineMIME = function(mime, spec) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2038 mimeModes[mime] = spec;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2039 };
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2040 CodeMirror.resolveMode = function(spec) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2041 if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2042 spec = mimeModes[spec];
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2043 else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec))
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2044 return CodeMirror.resolveMode("application/xml");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2045 if (typeof spec == "string") return {name: spec};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2046 else return spec || {name: "null"};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2047 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2048 CodeMirror.getMode = function(options, spec) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2049 var spec = CodeMirror.resolveMode(spec);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2050 var mfactory = modes[spec.name];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2051 if (!mfactory) return CodeMirror.getMode(options, "text/plain");
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2052 var modeObj = mfactory(options, spec);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2053 if (modeExtensions.hasOwnProperty(spec.name)) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2054 var exts = modeExtensions[spec.name];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2055 for (var prop in exts) if (exts.hasOwnProperty(prop)) modeObj[prop] = exts[prop];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2056 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2057 modeObj.name = spec.name;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2058 return modeObj;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2059 };
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2060 CodeMirror.listModes = function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2061 var list = [];
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2062 for (var m in modes)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2063 if (modes.propertyIsEnumerable(m)) list.push(m);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2064 return list;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2065 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2066 CodeMirror.listMIMEs = function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2067 var list = [];
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2068 for (var m in mimeModes)
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2069 if (mimeModes.propertyIsEnumerable(m)) list.push({mime: m, mode: mimeModes[m]});
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2070 return list;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2071 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2072
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2073 var extensions = CodeMirror.extensions = {};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2074 CodeMirror.defineExtension = function(name, func) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2075 extensions[name] = func;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2076 };
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2077
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2078 var modeExtensions = CodeMirror.modeExtensions = {};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2079 CodeMirror.extendMode = function(mode, properties) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2080 var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2081 for (var prop in properties) if (properties.hasOwnProperty(prop))
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2082 exts[prop] = properties[prop];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2083 };
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2084
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2085 var commands = CodeMirror.commands = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2086 selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2087 killLine: function(cm) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2088 var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2089 if (!sel && cm.getLine(from.line).length == from.ch) cm.replaceRange("", from, {line: from.line + 1, ch: 0});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2090 else cm.replaceRange("", from, sel ? to : {line: from.line});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2091 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2092 deleteLine: function(cm) {var l = cm.getCursor().line; cm.replaceRange("", {line: l, ch: 0}, {line: l});},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2093 undo: function(cm) {cm.undo();},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2094 redo: function(cm) {cm.redo();},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2095 goDocStart: function(cm) {cm.setCursor(0, 0, true);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2096 goDocEnd: function(cm) {cm.setSelection({line: cm.lineCount() - 1}, null, true);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2097 goLineStart: function(cm) {cm.setCursor(cm.getCursor().line, 0, true);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2098 goLineStartSmart: function(cm) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2099 var cur = cm.getCursor();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2100 var text = cm.getLine(cur.line), firstNonWS = Math.max(0, text.search(/\S/));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2101 cm.setCursor(cur.line, cur.ch <= firstNonWS && cur.ch ? 0 : firstNonWS, true);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2102 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2103 goLineEnd: function(cm) {cm.setSelection({line: cm.getCursor().line}, null, true);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2104 goLineUp: function(cm) {cm.moveV(-1, "line");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2105 goLineDown: function(cm) {cm.moveV(1, "line");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2106 goPageUp: function(cm) {cm.moveV(-1, "page");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2107 goPageDown: function(cm) {cm.moveV(1, "page");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2108 goCharLeft: function(cm) {cm.moveH(-1, "char");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2109 goCharRight: function(cm) {cm.moveH(1, "char");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2110 goColumnLeft: function(cm) {cm.moveH(-1, "column");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2111 goColumnRight: function(cm) {cm.moveH(1, "column");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2112 goWordLeft: function(cm) {cm.moveH(-1, "word");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2113 goWordRight: function(cm) {cm.moveH(1, "word");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2114 delCharLeft: function(cm) {cm.deleteH(-1, "char");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2115 delCharRight: function(cm) {cm.deleteH(1, "char");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2116 delWordLeft: function(cm) {cm.deleteH(-1, "word");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2117 delWordRight: function(cm) {cm.deleteH(1, "word");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2118 indentAuto: function(cm) {cm.indentSelection("smart");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2119 indentMore: function(cm) {cm.indentSelection("add");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2120 indentLess: function(cm) {cm.indentSelection("subtract");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2121 insertTab: function(cm) {cm.replaceSelection("\t", "end");},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2122 defaultTab: function(cm) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2123 if (cm.somethingSelected()) cm.indentSelection("add");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2124 else cm.replaceSelection("\t", "end");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2125 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2126 transposeChars: function(cm) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2127 var cur = cm.getCursor(), line = cm.getLine(cur.line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2128 if (cur.ch > 0 && cur.ch < line.length - 1)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2129 cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2130 {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2131 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2132 newlineAndIndent: function(cm) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2133 cm.replaceSelection("\n", "end");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2134 cm.indentLine(cm.getCursor().line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2135 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2136 toggleOverwrite: function(cm) {cm.toggleOverwrite();}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2137 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2138
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2139 var keyMap = CodeMirror.keyMap = {};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2140 keyMap.basic = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2141 "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2142 "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2143 "Delete": "delCharRight", "Backspace": "delCharLeft", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2144 "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2145 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2146 // Note that the save and find-related commands aren't defined by
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2147 // default. Unknown commands are simply ignored.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2148 keyMap.pcDefault = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2149 "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2150 "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2151 "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2152 "Ctrl-Backspace": "delWordLeft", "Ctrl-Delete": "delWordRight", "Ctrl-S": "save", "Ctrl-F": "find",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2153 "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2154 "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2155 fallthrough: "basic"
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2156 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2157 keyMap.macDefault = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2158 "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2159 "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2160 "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordLeft",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2161 "Ctrl-Alt-Backspace": "delWordRight", "Alt-Delete": "delWordRight", "Cmd-S": "save", "Cmd-F": "find",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2162 "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2163 "Cmd-[": "indentLess", "Cmd-]": "indentMore",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2164 fallthrough: ["basic", "emacsy"]
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2165 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2166 keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2167 keyMap.emacsy = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2168 "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2169 "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2170 "Ctrl-V": "goPageUp", "Shift-Ctrl-V": "goPageDown", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2171 "Alt-D": "delWordRight", "Alt-Backspace": "delWordLeft", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2172 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2173
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2174 function getKeyMap(val) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2175 if (typeof val == "string") return keyMap[val];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2176 else return val;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2177 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2178 function lookupKey(name, extraMap, map, handle, stop) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2179 function lookup(map) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2180 map = getKeyMap(map);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2181 var found = map[name];
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2182 if (found === false) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2183 if (stop) stop();
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2184 return true;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2185 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2186 if (found != null && handle(found)) return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2187 if (map.nofallthrough) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2188 if (stop) stop();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2189 return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2190 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2191 var fallthrough = map.fallthrough;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2192 if (fallthrough == null) return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2193 if (Object.prototype.toString.call(fallthrough) != "[object Array]")
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2194 return lookup(fallthrough);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2195 for (var i = 0, e = fallthrough.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2196 if (lookup(fallthrough[i])) return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2197 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2198 return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2199 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2200 if (extraMap && lookup(extraMap)) return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2201 return lookup(map);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2202 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2203 function isModifierKey(event) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2204 var name = keyNames[e_prop(event, "keyCode")];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2205 return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2206 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2207
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2208 CodeMirror.fromTextArea = function(textarea, options) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2209 if (!options) options = {};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2210 options.value = textarea.value;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2211 if (!options.tabindex && textarea.tabindex)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2212 options.tabindex = textarea.tabindex;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2213 // Set autofocus to true if this textarea is focused, or if it has
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2214 // autofocus and no other element is focused.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2215 if (options.autofocus == null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2216 var hasFocus = document.body;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2217 // doc.activeElement occasionally throws on IE
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2218 try { hasFocus = document.activeElement; } catch(e) {}
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2219 options.autofocus = hasFocus == textarea ||
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2220 textarea.getAttribute("autofocus") != null && hasFocus == document.body;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2221 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2222
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2223 function save() {textarea.value = instance.getValue();}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2224 if (textarea.form) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2225 // Deplorable hack to make the submit method do the right thing.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2226 var rmSubmit = connect(textarea.form, "submit", save, true);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2227 if (typeof textarea.form.submit == "function") {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2228 var realSubmit = textarea.form.submit;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2229 textarea.form.submit = function wrappedSubmit() {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2230 save();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2231 textarea.form.submit = realSubmit;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2232 textarea.form.submit();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2233 textarea.form.submit = wrappedSubmit;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2234 };
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2235 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2236 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2237
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2238 textarea.style.display = "none";
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2239 var instance = CodeMirror(function(node) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2240 textarea.parentNode.insertBefore(node, textarea.nextSibling);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2241 }, options);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2242 instance.save = save;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2243 instance.getTextArea = function() { return textarea; };
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2244 instance.toTextArea = function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2245 save();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2246 textarea.parentNode.removeChild(instance.getWrapperElement());
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2247 textarea.style.display = "";
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2248 if (textarea.form) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2249 rmSubmit();
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2250 if (typeof textarea.form.submit == "function")
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2251 textarea.form.submit = realSubmit;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2252 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2253 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2254 return instance;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2255 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2256
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2257 var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2258 var ie = /MSIE \d/.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2259 var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2260 var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2261 var quirksMode = ie && document.documentMode == 5;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2262 var webkit = /WebKit\//.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2263 var chrome = /Chrome\//.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2264 var opera = /Opera\//.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2265 var safari = /Apple Computer/.test(navigator.vendor);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2266 var khtml = /KHTML\//.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2267 var mac_geLion = /Mac OS X 10\D([7-9]|\d\d)\D/.test(navigator.userAgent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2268
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2269 // Utility functions for working with state. Exported because modes
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2270 // sometimes need to do this.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2271 function copyState(mode, state) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2272 if (state === true) return state;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2273 if (mode.copyState) return mode.copyState(state);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2274 var nstate = {};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2275 for (var n in state) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2276 var val = state[n];
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2277 if (val instanceof Array) val = val.concat([]);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2278 nstate[n] = val;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2279 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2280 return nstate;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2281 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2282 CodeMirror.copyState = copyState;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2283 function startState(mode, a1, a2) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2284 return mode.startState ? mode.startState(a1, a2) : true;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2285 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2286 CodeMirror.startState = startState;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2287 CodeMirror.innerMode = function(mode, state) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2288 while (mode.innerMode) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2289 var info = mode.innerMode(state);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2290 state = info.state;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2291 mode = info.mode;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2292 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2293 return info || {mode: mode, state: state};
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2294 };
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2295
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2296 // The character stream used by a mode's parser.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2297 function StringStream(string, tabSize) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2298 this.pos = this.start = 0;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2299 this.string = string;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2300 this.tabSize = tabSize || 8;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2301 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2302 StringStream.prototype = {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2303 eol: function() {return this.pos >= this.string.length;},
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2304 sol: function() {return this.pos == 0;},
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2305 peek: function() {return this.string.charAt(this.pos) || undefined;},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2306 next: function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2307 if (this.pos < this.string.length)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2308 return this.string.charAt(this.pos++);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2309 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2310 eat: function(match) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2311 var ch = this.string.charAt(this.pos);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2312 if (typeof match == "string") var ok = ch == match;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2313 else var ok = ch && (match.test ? match.test(ch) : match(ch));
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2314 if (ok) {++this.pos; return ch;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2315 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2316 eatWhile: function(match) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2317 var start = this.pos;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2318 while (this.eat(match)){}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2319 return this.pos > start;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2320 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2321 eatSpace: function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2322 var start = this.pos;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2323 while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2324 return this.pos > start;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2325 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2326 skipToEnd: function() {this.pos = this.string.length;},
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2327 skipTo: function(ch) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2328 var found = this.string.indexOf(ch, this.pos);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2329 if (found > -1) {this.pos = found; return true;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2330 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2331 backUp: function(n) {this.pos -= n;},
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2332 column: function() {return countColumn(this.string, this.start, this.tabSize);},
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2333 indentation: function() {return countColumn(this.string, null, this.tabSize);},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2334 match: function(pattern, consume, caseInsensitive) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2335 if (typeof pattern == "string") {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2336 var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2337 if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2338 if (consume !== false) this.pos += pattern.length;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2339 return true;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2340 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2341 } else {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2342 var match = this.string.slice(this.pos).match(pattern);
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2343 if (match && match.index > 0) return null;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2344 if (match && consume !== false) this.pos += match[0].length;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2345 return match;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2346 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2347 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2348 current: function(){return this.string.slice(this.start, this.pos);}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2349 };
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2350 CodeMirror.StringStream = StringStream;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2351
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2352 function MarkedSpan(from, to, marker) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2353 this.from = from; this.to = to; this.marker = marker;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2354 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2355
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2356 function getMarkedSpanFor(spans, marker, del) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2357 if (spans) for (var i = 0; i < spans.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2358 var span = spans[i];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2359 if (span.marker == marker) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2360 if (del) spans.splice(i, 1);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2361 return span;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2362 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2363 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2364 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2365
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2366 function markedSpansBefore(old, startCh, endCh) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2367 if (old) for (var i = 0, nw; i < old.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2368 var span = old[i], marker = span.marker;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2369 var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2370 if (startsBefore || marker.type == "bookmark" && span.from == startCh && span.from != endCh) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2371 var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2372 (nw || (nw = [])).push({from: span.from,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2373 to: endsAfter ? null : span.to,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2374 marker: marker});
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2375 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2376 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2377 return nw;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2378 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2379
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2380 function markedSpansAfter(old, endCh) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2381 if (old) for (var i = 0, nw; i < old.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2382 var span = old[i], marker = span.marker;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2383 var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2384 if (endsAfter || marker.type == "bookmark" && span.from == endCh) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2385 var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2386 (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2387 to: span.to == null ? null : span.to - endCh,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2388 marker: marker});
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2389 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2390 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2391 return nw;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2392 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2393
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2394 function updateMarkedSpans(oldFirst, oldLast, startCh, endCh, newText) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2395 if (!oldFirst && !oldLast) return newText;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2396 // Get the spans that 'stick out' on both sides
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2397 var first = markedSpansBefore(oldFirst, startCh);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2398 var last = markedSpansAfter(oldLast, endCh);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2399
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2400 // Next, merge those two ends
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2401 var sameLine = newText.length == 1, offset = lst(newText).length + (sameLine ? startCh : 0);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2402 if (first) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2403 // Fix up .to properties of first
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2404 for (var i = 0; i < first.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2405 var span = first[i];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2406 if (span.to == null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2407 var found = getMarkedSpanFor(last, span.marker);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2408 if (!found) span.to = startCh;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2409 else if (sameLine) span.to = found.to == null ? null : found.to + offset;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2410 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2411 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2412 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2413 if (last) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2414 // Fix up .from in last (or move them into first in case of sameLine)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2415 for (var i = 0; i < last.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2416 var span = last[i];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2417 if (span.to != null) span.to += offset;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2418 if (span.from == null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2419 var found = getMarkedSpanFor(first, span.marker);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2420 if (!found) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2421 span.from = offset;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2422 if (sameLine) (first || (first = [])).push(span);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2423 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2424 } else {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2425 span.from += offset;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2426 if (sameLine) (first || (first = [])).push(span);
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2427 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2428 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2429 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2430
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2431 var newMarkers = [newHL(newText[0], first)];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2432 if (!sameLine) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2433 // Fill gap with whole-line-spans
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2434 var gap = newText.length - 2, gapMarkers;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2435 if (gap > 0 && first)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2436 for (var i = 0; i < first.length; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2437 if (first[i].to == null)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2438 (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2439 for (var i = 0; i < gap; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2440 newMarkers.push(newHL(newText[i+1], gapMarkers));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2441 newMarkers.push(newHL(lst(newText), last));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2442 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2443 return newMarkers;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2444 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2445
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2446 // hl stands for history-line, a data structure that can be either a
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2447 // string (line without markers) or a {text, markedSpans} object.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2448 function hlText(val) { return typeof val == "string" ? val : val.text; }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2449 function hlSpans(val) { return typeof val == "string" ? null : val.markedSpans; }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2450 function newHL(text, spans) { return spans ? {text: text, markedSpans: spans} : text; }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2451
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2452 function detachMarkedSpans(line) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2453 var spans = line.markedSpans;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2454 if (!spans) return;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2455 for (var i = 0; i < spans.length; ++i) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2456 var lines = spans[i].marker.lines;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2457 var ix = indexOf(lines, line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2458 lines.splice(ix, 1);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2459 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2460 line.markedSpans = null;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2461 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2462
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2463 function attachMarkedSpans(line, spans) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2464 if (!spans) return;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2465 for (var i = 0; i < spans.length; ++i)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2466 var marker = spans[i].marker.lines.push(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2467 line.markedSpans = spans;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2468 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2469
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2470 // When measuring the position of the end of a line, different
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2471 // browsers require different approaches. If an empty span is added,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2472 // many browsers report bogus offsets. Of those, some (Webkit,
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2473 // recent IE) will accept a space without moving the whole span to
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2474 // the next line when wrapping it, others work with a zero-width
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2475 // space.
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2476 var eolSpanContent = " ";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2477 if (gecko || (ie && !ie_lt8)) eolSpanContent = "\u200b";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2478 else if (opera) eolSpanContent = "";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2479
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2480 // Line objects. These hold state related to a line, including
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2481 // highlighting info (the styles array).
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2482 function Line(text, markedSpans) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2483 this.text = text;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2484 this.height = 1;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2485 attachMarkedSpans(this, markedSpans);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2486 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2487 Line.prototype = {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2488 update: function(text, markedSpans) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2489 this.text = text;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2490 this.stateAfter = this.styles = null;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2491 detachMarkedSpans(this);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2492 attachMarkedSpans(this, markedSpans);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2493 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2494 // Run the given mode's parser over a line, update the styles
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2495 // array, which contains alternating fragments of text and CSS
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2496 // classes.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2497 highlight: function(mode, state, tabSize) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2498 var stream = new StringStream(this.text, tabSize), st = this.styles || (this.styles = []);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2499 var pos = st.length = 0;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2500 if (this.text == "" && mode.blankLine) mode.blankLine(state);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2501 while (!stream.eol()) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2502 var style = mode.token(stream, state), substr = stream.current();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2503 stream.start = stream.pos;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2504 if (pos && st[pos-1] == style) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2505 st[pos-2] += substr;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2506 } else if (substr) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2507 st[pos++] = substr; st[pos++] = style;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2508 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2509 // Give up when line is ridiculously long
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2510 if (stream.pos > 5000) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2511 st[pos++] = this.text.slice(stream.pos); st[pos++] = null;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2512 break;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2513 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2514 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2515 },
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2516 process: function(mode, state, tabSize) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2517 var stream = new StringStream(this.text, tabSize);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2518 if (this.text == "" && mode.blankLine) mode.blankLine(state);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2519 while (!stream.eol() && stream.pos <= 5000) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2520 mode.token(stream, state);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2521 stream.start = stream.pos;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2522 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2523 },
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2524 // Fetch the parser token for a given character. Useful for hacks
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2525 // that want to inspect the mode state (say, for completion).
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2526 getTokenAt: function(mode, state, tabSize, ch) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2527 var txt = this.text, stream = new StringStream(txt, tabSize);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2528 while (stream.pos < ch && !stream.eol()) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2529 stream.start = stream.pos;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2530 var style = mode.token(stream, state);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2531 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2532 return {start: stream.start,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2533 end: stream.pos,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2534 string: stream.current(),
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2535 className: style || null,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2536 state: state};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2537 },
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2538 indentation: function(tabSize) {return countColumn(this.text, null, tabSize);},
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2539 // Produces an HTML fragment for the line, taking selection,
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2540 // marking, and highlighting into account.
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2541 getContent: function(tabSize, wrapAt, compensateForWrapping) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2542 var first = true, col = 0, specials = /[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2543 var pre = elt("pre");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2544 function span_(html, text, style) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2545 if (!text) return;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2546 // Work around a bug where, in some compat modes, IE ignores leading spaces
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2547 if (first && ie && text.charAt(0) == " ") text = "\u00a0" + text.slice(1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2548 first = false;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2549 if (!specials.test(text)) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2550 col += text.length;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2551 var content = document.createTextNode(text);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2552 } else {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2553 var content = document.createDocumentFragment(), pos = 0;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2554 while (true) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2555 specials.lastIndex = pos;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2556 var m = specials.exec(text);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2557 var skipped = m ? m.index - pos : text.length - pos;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2558 if (skipped) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2559 content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2560 col += skipped;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2561 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2562 if (!m) break;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2563 pos += skipped + 1;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2564 if (m[0] == "\t") {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2565 var tabWidth = tabSize - col % tabSize;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2566 content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2567 col += tabWidth;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2568 } else {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2569 var token = elt("span", "\u2022", "cm-invalidchar");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2570 token.title = "\\u" + m[0].charCodeAt(0).toString(16);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2571 content.appendChild(token);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2572 col += 1;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2573 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2574 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2575 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2576 if (style) html.appendChild(elt("span", [content], style));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2577 else html.appendChild(content);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2578 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2579 var span = span_;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2580 if (wrapAt != null) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2581 var outPos = 0, anchor = pre.anchor = elt("span");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2582 span = function(html, text, style) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2583 var l = text.length;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2584 if (wrapAt >= outPos && wrapAt < outPos + l) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2585 if (wrapAt > outPos) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2586 span_(html, text.slice(0, wrapAt - outPos), style);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2587 // See comment at the definition of spanAffectsWrapping
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2588 if (compensateForWrapping) html.appendChild(elt("wbr"));
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2589 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2590 html.appendChild(anchor);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2591 var cut = wrapAt - outPos;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2592 span_(anchor, opera ? text.slice(cut, cut + 1) : text.slice(cut), style);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2593 if (opera) span_(html, text.slice(cut + 1), style);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2594 wrapAt--;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2595 outPos += l;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2596 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2597 outPos += l;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2598 span_(html, text, style);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2599 if (outPos == wrapAt && outPos == len) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2600 setTextContent(anchor, eolSpanContent);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2601 html.appendChild(anchor);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2602 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2603 // Stop outputting HTML when gone sufficiently far beyond measure
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2604 else if (outPos > wrapAt + 10 && /\s/.test(text)) span = function(){};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2605 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2606 };
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2607 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2608
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2609 var st = this.styles, allText = this.text, marked = this.markedSpans;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2610 var len = allText.length;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2611 function styleToClass(style) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2612 if (!style) return null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2613 return "cm-" + style.replace(/ +/g, " cm-");
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2614 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2615 if (!allText && wrapAt == null) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2616 span(pre, " ");
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2617 } else if (!marked || !marked.length) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2618 for (var i = 0, ch = 0; ch < len; i+=2) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2619 var str = st[i], style = st[i+1], l = str.length;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2620 if (ch + l > len) str = str.slice(0, len - ch);
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2621 ch += l;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2622 span(pre, str, styleToClass(style));
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2623 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2624 } else {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2625 marked.sort(function(a, b) { return a.from - b.from; });
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2626 var pos = 0, i = 0, text = "", style, sg = 0;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2627 var nextChange = marked[0].from || 0, marks = [], markpos = 0;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2628 var advanceMarks = function() {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2629 var m;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2630 while (markpos < marked.length &&
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2631 ((m = marked[markpos]).from == pos || m.from == null)) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2632 if (m.marker.type == "range") marks.push(m);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2633 ++markpos;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2634 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2635 nextChange = markpos < marked.length ? marked[markpos].from : Infinity;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2636 for (var i = 0; i < marks.length; ++i) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2637 var to = marks[i].to;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2638 if (to == null) to = Infinity;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2639 if (to == pos) marks.splice(i--, 1);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2640 else nextChange = Math.min(to, nextChange);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2641 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2642 };
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2643 var m = 0;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2644 while (pos < len) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2645 if (nextChange == pos) advanceMarks();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2646 var upto = Math.min(len, nextChange);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2647 while (true) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2648 if (text) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2649 var end = pos + text.length;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2650 var appliedStyle = style;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2651 for (var j = 0; j < marks.length; ++j) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2652 var mark = marks[j];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2653 appliedStyle = (appliedStyle ? appliedStyle + " " : "") + mark.marker.style;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2654 if (mark.marker.endStyle && mark.to === Math.min(end, upto)) appliedStyle += " " + mark.marker.endStyle;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2655 if (mark.marker.startStyle && mark.from === pos) appliedStyle += " " + mark.marker.startStyle;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2656 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2657 span(pre, end > upto ? text.slice(0, upto - pos) : text, appliedStyle);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2658 if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2659 pos = end;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2660 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2661 text = st[i++]; style = styleToClass(st[i++]);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2662 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2663 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2664 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2665 return pre;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2666 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2667 cleanUp: function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2668 this.parent = null;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2669 detachMarkedSpans(this);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2670 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2671 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2672
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2673 // Data structure that holds the sequence of lines.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2674 function LeafChunk(lines) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2675 this.lines = lines;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2676 this.parent = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2677 for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2678 lines[i].parent = this;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2679 height += lines[i].height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2680 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2681 this.height = height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2682 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2683 LeafChunk.prototype = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2684 chunkSize: function() { return this.lines.length; },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2685 remove: function(at, n, callbacks) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2686 for (var i = at, e = at + n; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2687 var line = this.lines[i];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2688 this.height -= line.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2689 line.cleanUp();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2690 if (line.handlers)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2691 for (var j = 0; j < line.handlers.length; ++j) callbacks.push(line.handlers[j]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2692 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2693 this.lines.splice(at, n);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2694 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2695 collapse: function(lines) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2696 lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2697 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2698 insertHeight: function(at, lines, height) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2699 this.height += height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2700 this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2701 for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2702 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2703 iterN: function(at, n, op) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2704 for (var e = at + n; at < e; ++at)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2705 if (op(this.lines[at])) return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2706 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2707 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2708 function BranchChunk(children) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2709 this.children = children;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2710 var size = 0, height = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2711 for (var i = 0, e = children.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2712 var ch = children[i];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2713 size += ch.chunkSize(); height += ch.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2714 ch.parent = this;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2715 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2716 this.size = size;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2717 this.height = height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2718 this.parent = null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2719 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2720 BranchChunk.prototype = {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2721 chunkSize: function() { return this.size; },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2722 remove: function(at, n, callbacks) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2723 this.size -= n;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2724 for (var i = 0; i < this.children.length; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2725 var child = this.children[i], sz = child.chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2726 if (at < sz) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2727 var rm = Math.min(n, sz - at), oldHeight = child.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2728 child.remove(at, rm, callbacks);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2729 this.height -= oldHeight - child.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2730 if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2731 if ((n -= rm) == 0) break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2732 at = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2733 } else at -= sz;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2734 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2735 if (this.size - n < 25) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2736 var lines = [];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2737 this.collapse(lines);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2738 this.children = [new LeafChunk(lines)];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2739 this.children[0].parent = this;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2740 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2741 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2742 collapse: function(lines) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2743 for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2744 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2745 insert: function(at, lines) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2746 var height = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2747 for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2748 this.insertHeight(at, lines, height);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2749 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2750 insertHeight: function(at, lines, height) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2751 this.size += lines.length;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2752 this.height += height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2753 for (var i = 0, e = this.children.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2754 var child = this.children[i], sz = child.chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2755 if (at <= sz) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2756 child.insertHeight(at, lines, height);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2757 if (child.lines && child.lines.length > 50) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2758 while (child.lines.length > 50) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2759 var spilled = child.lines.splice(child.lines.length - 25, 25);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2760 var newleaf = new LeafChunk(spilled);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2761 child.height -= newleaf.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2762 this.children.splice(i + 1, 0, newleaf);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2763 newleaf.parent = this;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2764 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2765 this.maybeSpill();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2766 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2767 break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2768 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2769 at -= sz;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2770 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2771 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2772 maybeSpill: function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2773 if (this.children.length <= 10) return;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2774 var me = this;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2775 do {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2776 var spilled = me.children.splice(me.children.length - 5, 5);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2777 var sibling = new BranchChunk(spilled);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2778 if (!me.parent) { // Become the parent node
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2779 var copy = new BranchChunk(me.children);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2780 copy.parent = me;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2781 me.children = [copy, sibling];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2782 me = copy;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2783 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2784 me.size -= sibling.size;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2785 me.height -= sibling.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2786 var myIndex = indexOf(me.parent.children, me);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2787 me.parent.children.splice(myIndex + 1, 0, sibling);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2788 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2789 sibling.parent = me.parent;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2790 } while (me.children.length > 10);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2791 me.parent.maybeSpill();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2792 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2793 iter: function(from, to, op) { this.iterN(from, to - from, op); },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2794 iterN: function(at, n, op) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2795 for (var i = 0, e = this.children.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2796 var child = this.children[i], sz = child.chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2797 if (at < sz) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2798 var used = Math.min(n, sz - at);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2799 if (child.iterN(at, used, op)) return true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2800 if ((n -= used) == 0) break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2801 at = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2802 } else at -= sz;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2803 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2804 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2805 };
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2806
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2807 function getLineAt(chunk, n) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2808 while (!chunk.lines) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2809 for (var i = 0;; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2810 var child = chunk.children[i], sz = child.chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2811 if (n < sz) { chunk = child; break; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2812 n -= sz;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2813 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2814 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2815 return chunk.lines[n];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2816 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2817 function lineNo(line) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2818 if (line.parent == null) return null;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2819 var cur = line.parent, no = indexOf(cur.lines, line);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2820 for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2821 for (var i = 0, e = chunk.children.length; ; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2822 if (chunk.children[i] == cur) break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2823 no += chunk.children[i].chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2824 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2825 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2826 return no;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2827 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2828 function lineAtHeight(chunk, h) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2829 var n = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2830 outer: do {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2831 for (var i = 0, e = chunk.children.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2832 var child = chunk.children[i], ch = child.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2833 if (h < ch) { chunk = child; continue outer; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2834 h -= ch;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2835 n += child.chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2836 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2837 return n;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2838 } while (!chunk.lines);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2839 for (var i = 0, e = chunk.lines.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2840 var line = chunk.lines[i], lh = line.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2841 if (h < lh) break;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2842 h -= lh;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2843 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2844 return n + i;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2845 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2846 function heightAtLine(chunk, n) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2847 var h = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2848 outer: do {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2849 for (var i = 0, e = chunk.children.length; i < e; ++i) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2850 var child = chunk.children[i], sz = child.chunkSize();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2851 if (n < sz) { chunk = child; continue outer; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2852 n -= sz;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2853 h += child.height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2854 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2855 return h;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2856 } while (!chunk.lines);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2857 for (var i = 0; i < n; ++i) h += chunk.lines[i].height;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2858 return h;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2859 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2860
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2861 // The history object 'chunks' changes that are made close together
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2862 // and at almost the same time into bigger undoable units.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2863 function History() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2864 this.time = 0;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2865 this.done = []; this.undone = [];
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2866 this.compound = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2867 this.closed = false;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2868 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2869 History.prototype = {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2870 addChange: function(start, added, old) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2871 this.undone.length = 0;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2872 var time = +new Date, cur = lst(this.done), last = cur && lst(cur);
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2873 var dtime = time - this.time;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2874
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2875 if (this.compound && cur && !this.closed) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2876 cur.push({start: start, added: added, old: old});
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2877 } else if (dtime > 400 || !last || this.closed ||
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2878 last.start > start + old.length || last.start + last.added < start) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2879 this.done.push([{start: start, added: added, old: old}]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2880 this.closed = false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2881 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2882 var startBefore = Math.max(0, last.start - start),
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2883 endAfter = Math.max(0, (start + old.length) - (last.start + last.added));
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2884 for (var i = startBefore; i > 0; --i) last.old.unshift(old[i - 1]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2885 for (var i = endAfter; i > 0; --i) last.old.push(old[old.length - i]);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2886 if (startBefore) last.start = start;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2887 last.added += added - (old.length - startBefore - endAfter);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2888 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2889 this.time = time;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2890 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2891 startCompound: function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2892 if (!this.compound++) this.closed = true;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2893 },
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2894 endCompound: function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2895 if (!--this.compound) this.closed = true;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2896 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2897 };
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2898
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2899 function stopMethod() {e_stop(this);}
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2900 // Ensure an event has a stop method.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2901 function addStop(event) {
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2902 if (!event.stop) event.stop = stopMethod;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2903 return event;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2904 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2905
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2906 function e_preventDefault(e) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2907 if (e.preventDefault) e.preventDefault();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2908 else e.returnValue = false;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2909 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2910 function e_stopPropagation(e) {
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2911 if (e.stopPropagation) e.stopPropagation();
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2912 else e.cancelBubble = true;
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2913 }
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2914 function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2915 CodeMirror.e_stop = e_stop;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2916 CodeMirror.e_preventDefault = e_preventDefault;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2917 CodeMirror.e_stopPropagation = e_stopPropagation;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2918
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2919 function e_target(e) {return e.target || e.srcElement;}
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2920 function e_button(e) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2921 var b = e.which;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2922 if (b == null) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2923 if (e.button & 1) b = 1;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2924 else if (e.button & 2) b = 3;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2925 else if (e.button & 4) b = 2;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2926 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2927 if (mac && e.ctrlKey && b == 1) b = 3;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2928 return b;
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2929 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2930
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2931 // Allow 3rd-party code to override event properties by adding an override
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2932 // object to an event object.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2933 function e_prop(e, prop) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2934 var overridden = e.override && e.override.hasOwnProperty(prop);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2935 return overridden ? e.override[prop] : e[prop];
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2936 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2937
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2938 // Event handler registration. If disconnect is true, it'll return a
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2939 // function that unregisters the handler.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2940 function connect(node, type, handler, disconnect) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2941 if (typeof node.addEventListener == "function") {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2942 node.addEventListener(type, handler, false);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2943 if (disconnect) return function() {node.removeEventListener(type, handler, false);};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2944 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2945 var wrapHandler = function(event) {handler(event || window.event);};
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2946 node.attachEvent("on" + type, wrapHandler);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2947 if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2948 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2949 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2950 CodeMirror.connect = connect;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2951
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2952 function Delayed() {this.id = null;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2953 Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2954
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2955 var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
2956
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2957 // Detect drag-and-drop
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2958 var dragAndDrop = function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2959 // There is *some* kind of drag-and-drop support in IE6-8, but I
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2960 // couldn't get it to work yet.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2961 if (ie_lt9) return false;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2962 var div = elt('div');
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2963 return "draggable" in div || "dragDrop" in div;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2964 }();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2965
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2966 // Feature-detect whether newlines in textareas are converted to \r\n
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2967 var lineSep = function () {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
2968 var te = elt("textarea");
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2969 te.value = "foo\nbar";
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2970 if (te.value.indexOf("\r") > -1) return "\r\n";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2971 return "\n";
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2972 }();
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2973
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2974 // For a reason I have yet to figure out, some browsers disallow
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2975 // word wrapping between certain characters *only* if a new inline
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2976 // element is started between them. This makes it hard to reliably
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2977 // measure the position of things, since that requires inserting an
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2978 // extra span. This terribly fragile set of regexps matches the
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2979 // character combinations that suffer from this phenomenon on the
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2980 // various browsers.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2981 var spanAffectsWrapping = /^$/; // Won't match any two-character string
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2982 if (gecko) spanAffectsWrapping = /$'/;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2983 else if (safari) spanAffectsWrapping = /\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2984 else if (chrome) spanAffectsWrapping = /\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2985
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2986 // Counts the column offset in a string, taking tabs into account.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2987 // Used mostly to find indentation.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
2988 function countColumn(string, end, tabSize) {
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2989 if (end == null) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2990 end = string.search(/[^\s\u00a0]/);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2991 if (end == -1) end = string.length;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2992 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2993 for (var i = 0, n = 0; i < end; ++i) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2994 if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2995 else ++n;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2996 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2997 return n;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2998 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2999
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
3000 function eltOffset(node, screen) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3001 // Take the parts of bounding client rect that we are interested in so we are able to edit if need be,
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3002 // since the returned value cannot be changed externally (they are kept in sync as the element moves within the page)
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3003 try { var box = node.getBoundingClientRect(); box = { top: box.top, left: box.left }; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3004 catch(e) { box = {top: 0, left: 0}; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3005 if (!screen) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3006 // Get the toplevel scroll, working around browser differences.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3007 if (window.pageYOffset == null) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3008 var t = document.documentElement || document.body.parentNode;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3009 if (t.scrollTop == null) t = document.body;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3010 box.top += t.scrollTop; box.left += t.scrollLeft;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3011 } else {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3012 box.top += window.pageYOffset; box.left += window.pageXOffset;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3013 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3014 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3015 return box;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3016 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3017
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3018 function eltText(node) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3019 return node.textContent || node.innerText || node.nodeValue || "";
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3020 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3021
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3022 var spaceStrs = [""];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3023 function spaceStr(n) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3024 while (spaceStrs.length <= n)
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3025 spaceStrs.push(lst(spaceStrs) + " ");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3026 return spaceStrs[n];
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3027 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3028
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3029 function lst(arr) { return arr[arr.length-1]; }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3030
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3031 function selectInput(node) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3032 if (ios) { // Mobile Safari apparently has a bug where select() is broken.
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3033 node.selectionStart = 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3034 node.selectionEnd = node.value.length;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3035 } else node.select();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3036 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3037
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3038 // Operations on {line, ch} objects.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3039 function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3040 function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3041 function copyPos(x) {return {line: x.line, ch: x.ch};}
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3042
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3043 function elt(tag, content, className, style) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3044 var e = document.createElement(tag);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3045 if (className) e.className = className;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3046 if (style) e.style.cssText = style;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3047 if (typeof content == "string") setTextContent(e, content);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3048 else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3049 return e;
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3050 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3051 function removeChildren(e) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3052 e.innerHTML = "";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3053 return e;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3054 }
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3055 function removeChildrenAndAdd(parent, e) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3056 removeChildren(parent).appendChild(e);
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3057 }
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3058 function setTextContent(e, str) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3059 if (ie_lt9) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3060 e.innerHTML = "";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3061 e.appendChild(document.createTextNode(str));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3062 } else e.textContent = str;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3063 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3064
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3065 // Used to position the cursor after an undo/redo by finding the
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3066 // last edited character.
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3067 function editEnd(from, to) {
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3068 if (!to) return 0;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3069 if (!from) return to.length;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3070 for (var i = from.length, j = to.length; i >= 0 && j >= 0; --i, --j)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3071 if (from.charAt(i) != to.charAt(j)) break;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3072 return j + 1;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3073 }
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3074
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3075 function indexOf(collection, elt) {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3076 if (collection.indexOf) return collection.indexOf(elt);
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3077 for (var i = 0, e = collection.length; i < e; ++i)
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3078 if (collection[i] == elt) return i;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3079 return -1;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3080 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3081 function isWordChar(ch) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3082 return /\w/.test(ch) || ch.toUpperCase() != ch.toLowerCase();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3083 }
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3084
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3085 // See if "".split is the broken IE version, if so, provide an
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3086 // alternative way to split lines.
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3087 var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3088 var pos = 0, result = [], l = string.length;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3089 while (pos <= l) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3090 var nl = string.indexOf("\n", pos);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3091 if (nl == -1) nl = string.length;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3092 var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3093 var rt = line.indexOf("\r");
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3094 if (rt != -1) {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3095 result.push(line.slice(0, rt));
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3096 pos += rt + 1;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3097 } else {
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3098 result.push(line);
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3099 pos = nl + 1;
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3100 }
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3101 }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3102 return result;
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3103 } : function(string){return string.split(/\r\n?|\n/);};
1606
a30689fc4f61 bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 1305
diff changeset
3104 CodeMirror.splitLines = splitLines;
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3105
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3106 var hasSelection = window.getSelection ? function(te) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3107 try { return te.selectionStart != te.selectionEnd; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3108 catch(e) { return false; }
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3109 } : function(te) {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3110 try {var range = te.ownerDocument.selection.createRange();}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3111 catch(e) {}
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3112 if (!range || range.parentElement() != te) return false;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3113 return range.compareEndPoints("StartToEnd", range) != 0;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3114 };
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3115
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3116 CodeMirror.defineMode("null", function() {
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3117 return {token: function(stream) {stream.skipToEnd();}};
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3118 });
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3119 CodeMirror.defineMIME("text/plain", "null");
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3120
2547
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3121 var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3122 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3123 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3124 46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3125 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3126 221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3127 63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3128 CodeMirror.keyNames = keyNames;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3129 (function() {
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3130 // Number keys
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3131 for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3132 // Alphabetic keys
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3133 for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3134 // Function keys
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3135 for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3136 })();
01273e4f8d63 Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents: 1606
diff changeset
3137
2861
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3138 CodeMirror.version = "2.34";
f034e6a13a5e updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents: 2547
diff changeset
3139
1305
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3140 return CodeMirror;
166317d464f3 Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3141 })();