Mercurial > kallithea
annotate rhodecode/public/js/codemirror.js @ 3237:f5dd76e2a7af beta
disable file editing when not on branch head fixes issue #462
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 27 Jan 2013 00:18:49 +0100 |
parents | 31f98c850623 |
children | cd23cc2c9961 |
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, |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
78 overwrite = false, suppressEdits = false, pasteIncoming = 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();}); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
131 connect(input, "paste", function(){pasteIncoming = true; fastPoll();}); |
2547
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(); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
170 else if (option == "tabindex") input.tabIndex = value; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
171 if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" || |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
172 option == "theme" || option == "lineNumberFormatter") { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
173 gutterChanged(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
174 updateDisplay(true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
175 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 getOption: function(option) {return options[option];}, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
178 getMode: function() {return mode;}, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 undo: operation(undo), |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 redo: operation(redo), |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
181 indentLine: operation(function(n, dir) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
182 if (typeof dir != "string") { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
183 if (dir == null) dir = options.smartIndent ? "smart" : "prev"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
184 else dir = dir ? "add" : "subtract"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
185 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
186 if (isLine(n)) indentLine(n, dir); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
187 }), |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
188 indentSelection: operation(indentSelected), |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 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
|
190 clearHistory: function() {history = new History();}, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
191 setHistory: function(histData) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
192 history = new History(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
193 history.done = histData.done; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
194 history.undone = histData.undone; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
195 }, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
196 getHistory: function() { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
197 function cp(arr) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
198 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
|
199 nw.push(nwelt = []); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
200 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
|
201 var old = [], cur = elt[j]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
202 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
|
203 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
|
204 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
205 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
206 return nw; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
207 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
208 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
|
209 }, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 matchBrackets: operation(function(){matchBrackets(true);}), |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
211 getTokenAt: operation(function(pos) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 pos = clipPos(pos); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
213 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
|
214 }), |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
215 getStateAfter: function(line) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
216 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
|
217 return getStateBefore(line + 1); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
218 }, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
219 cursorCoords: function(start, mode) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
220 if (start == null) start = sel.inverted; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
221 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
|
222 }, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
223 charCoords: function(pos, mode) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
224 pos = clipPos(pos); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
225 if (mode == "local") return localCoords(pos, false); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
226 if (mode == "div") return localCoords(pos, true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
227 return pageCoords(pos); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
228 }, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
229 coordsChar: function(coords) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
230 var off = eltOffset(lineSpace); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
231 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
|
232 }, |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
233 defaultTextHeight: function() { return textHeight(); }, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
234 markText: operation(markText), |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
235 setBookmark: setBookmark, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
236 findMarksAt: findMarksAt, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
237 setMarker: operation(addGutterMarker), |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
238 clearMarker: operation(removeGutterMarker), |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
239 setLineClass: operation(setLineClass), |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
240 hideLine: operation(function(h) {return setLineHidden(h, true);}), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
241 showLine: operation(function(h) {return setLineHidden(h, false);}), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
242 onDeleteLine: function(line, f) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
243 if (typeof line == "number") { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
244 if (!isLine(line)) return null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
245 line = getLine(line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
246 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
247 (line.handlers || (line.handlers = [])).push(f); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
248 return line; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
249 }, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 lineInfo: lineInfo, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
251 getViewport: function() { return {from: showingFrom, to: showingTo};}, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
252 addWidget: function(pos, node, scroll, vert, horiz) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
253 pos = localCoords(clipPos(pos)); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
254 var top = pos.yBot, left = pos.x; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
255 node.style.position = "absolute"; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
256 sizer.appendChild(node); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
257 if (vert == "over") top = pos.y; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
258 else if (vert == "near") { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 top = pos.y - node.offsetHeight; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
263 if (left + node.offsetWidth > hspace) |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
264 left = hspace - node.offsetWidth; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
265 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
266 node.style.top = (top + paddingTop()) + "px"; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
267 node.style.left = node.style.right = ""; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
268 if (horiz == "right") { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
269 left = sizer.clientWidth - node.offsetWidth; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
270 node.style.right = "0px"; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
271 } else { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
272 if (horiz == "left") left = 0; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
273 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
|
274 node.style.left = (left + paddingLeft()) + "px"; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
275 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 if (scroll) |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
277 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
|
278 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
279 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
280 lineCount: function() {return doc.size;}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
281 clipPos: clipPos, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 getCursor: function(start) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
283 if (start == null) start = sel.inverted; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
284 return copyPos(start ? sel.from : sel.to); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 somethingSelected: function() {return !posEq(sel.from, sel.to);}, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
287 setCursor: operation(function(line, ch, user) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
288 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
|
289 else setCursor(line, ch, user); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 }), |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
291 setSelection: operation(function(from, to, user) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
292 (user ? setSelectionUser : setSelection)(clipPos(from), clipPos(to || from)); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
293 }), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
294 getLine: function(line) {if (isLine(line)) return getLine(line).text;}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
295 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
|
296 setLine: operation(function(line, text) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
297 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
|
298 }), |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 removeLine: operation(function(line) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
300 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
|
301 }), |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
302 replaceRange: operation(replaceRange), |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
303 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
|
304 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
305 triggerOnKeyDown: operation(onKeyDown), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
306 execCommand: function(cmd) {return commands[cmd](instance);}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
307 // 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
|
308 moveH: operation(moveH), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
309 deleteH: operation(deleteH), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
310 moveV: operation(moveV), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
311 toggleOverwrite: function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
312 if(overwrite){ |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
313 overwrite = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
314 cursor.className = cursor.className.replace(" CodeMirror-overwrite", ""); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
315 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
316 overwrite = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
317 cursor.className += " CodeMirror-overwrite"; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
318 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
319 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
320 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
321 posFromIndex: function(off) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
322 var lineNo = 0, ch; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
323 doc.iter(0, doc.size, function(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
324 var sz = line.text.length + 1; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
325 if (sz > off) { ch = off; return true; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
326 off -= sz; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
327 ++lineNo; |
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 return clipPos({line: lineNo, ch: ch}); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
330 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
331 indexFromPos: function (coords) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
332 if (coords.line < 0 || coords.ch < 0) return 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
333 var index = coords.ch; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
334 doc.iter(0, coords.line, function (line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
335 index += line.text.length + 1; |
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 return index; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
338 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
339 scrollTo: function(x, y) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
340 if (x != null) scroller.scrollLeft = x; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
341 if (y != null) scrollbar.scrollTop = scroller.scrollTop = y; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
342 updateDisplay([]); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
343 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
344 getScrollInfo: function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
345 return {x: scroller.scrollLeft, y: scrollbar.scrollTop, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
346 height: scrollbar.scrollHeight, width: scroller.scrollWidth}; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
347 }, |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
348 scrollIntoView: function(pos) { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
349 var coords = localCoords(pos ? clipPos(pos) : sel.inverted ? sel.from : sel.to); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
350 scrollIntoView(coords.x, coords.y, coords.x, coords.yBot); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
351 }, |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
352 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
353 setSize: function(width, height) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
354 function interpret(val) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
355 val = String(val); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
356 return /^\d+$/.test(val) ? val + "px" : val; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
357 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
358 if (width != null) wrapper.style.width = interpret(width); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
359 if (height != null) scroller.style.height = interpret(height); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
360 instance.refresh(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
361 }, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
362 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
363 operation: function(f){return operation(f)();}, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
364 compoundChange: function(f){return compoundChange(f);}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
365 refresh: function(){ |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
366 updateDisplay(true, null, lastScrollTop); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
367 if (scrollbar.scrollHeight > lastScrollTop) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
368 scrollbar.scrollTop = lastScrollTop; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
369 }, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
370 getInputField: function(){return input;}, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
371 getWrapperElement: function(){return wrapper;}, |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
372 getScrollerElement: function(){return scroller;}, |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
373 getGutterElement: function(){return gutter;} |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
374 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
375 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
376 function getLine(n) { return getLineAt(doc, n); } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
377 function updateLineHeight(line, height) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
378 gutterDirty = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
379 var diff = height - line.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
380 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
|
381 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
382 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
383 function lineContent(line, wrapAt) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
384 if (!line.styles) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
385 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
|
386 return line.getContent(options.tabSize, wrapAt, options.lineWrapping); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
387 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
388 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
389 function setValue(code) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
390 var top = {line: 0, ch: 0}; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
391 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
|
392 splitLines(code), top, top); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
393 updateInput = true; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
394 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
395 function getValue(lineSep) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
396 var text = []; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
397 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
|
398 return text.join(lineSep || "\n"); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
399 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
400 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
401 function onScrollBar(e) { |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
402 if (Math.abs(scrollbar.scrollTop - lastScrollTop) > 1) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
403 lastScrollTop = scroller.scrollTop = scrollbar.scrollTop; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
404 updateDisplay([]); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
405 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
406 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
407 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
408 function onScrollMain(e) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
409 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
|
410 gutter.style.left = scroller.scrollLeft + "px"; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
411 if (Math.abs(scroller.scrollTop - lastScrollTop) > 1) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
412 lastScrollTop = scroller.scrollTop; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
413 if (scrollbar.scrollTop != lastScrollTop) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
414 scrollbar.scrollTop = lastScrollTop; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
415 updateDisplay([]); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
416 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
417 if (options.onScroll) options.onScroll(instance); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
418 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
419 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
420 function onMouseDown(e) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
421 setShift(e_prop(e, "shiftKey")); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
422 // 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
|
423 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
|
424 if (n.parentNode == sizer && n != mover) return; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
425 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
426 // 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
|
427 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
|
428 if (n.parentNode == gutterText) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
429 if (options.onGutterClick) |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
430 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
|
431 return e_preventDefault(e); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
432 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
433 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
434 var start = posFromMouse(e); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
435 |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
436 switch (e_button(e)) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
437 case 3: |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
438 if (gecko) onContextMenu(e); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
439 return; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
440 case 2: |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
441 if (start) setCursor(start.line, start.ch, true); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
442 setTimeout(focusInput, 20); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
443 e_preventDefault(e); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
444 return; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
445 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
446 // 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
|
447 // (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
|
448 // selection. |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
449 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
|
450 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
451 if (!focused) onFocus(); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
452 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
453 var now = +new Date, type = "single"; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
454 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
|
455 type = "triple"; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
456 e_preventDefault(e); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
457 setTimeout(focusInput, 20); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
458 selectLine(start.line); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
459 } 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
|
460 type = "double"; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
461 lastDoubleClick = {time: now, pos: start}; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
462 e_preventDefault(e); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
463 var word = findWordAt(start); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
464 setSelectionUser(word.from, word.to); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
465 } else { lastClick = {time: now, pos: start}; } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
466 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
467 function dragEnd(e2) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
468 if (webkit) scroller.draggable = false; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
469 draggingText = false; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
470 up(); drop(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
471 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
|
472 e_preventDefault(e2); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
473 setCursor(start.line, start.ch, true); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
474 focusInput(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
475 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
476 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
477 var last = start, going; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
478 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
|
479 !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
|
480 // Let the drag handler handle this. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
481 if (webkit) scroller.draggable = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
482 var up = connect(document, "mouseup", operation(dragEnd), true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
483 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
|
484 draggingText = true; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
485 // IE's approach to draggable |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
486 if (scroller.dragDrop) scroller.dragDrop(); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
487 return; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
488 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
489 e_preventDefault(e); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
490 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
|
491 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
492 var startstart = sel.from, startend = sel.to; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
493 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
494 function doSelect(cur) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
495 if (type == "single") { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
496 setSelectionUser(start, cur); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
497 } else if (type == "double") { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
498 var word = findWordAt(cur); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
499 if (posLess(cur, startstart)) setSelectionUser(word.from, startend); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
500 else setSelectionUser(startstart, word.to); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
501 } else if (type == "triple") { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
502 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
|
503 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
|
504 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
505 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
506 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
507 function extend(e) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
508 var cur = posFromMouse(e, true); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
509 if (cur && !posEq(cur, last)) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
510 if (!focused) onFocus(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
511 last = cur; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
512 doSelect(cur); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
513 updateInput = false; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
514 var visible = visibleLines(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
515 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
|
516 going = setTimeout(operation(function(){extend(e);}), 150); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
517 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
518 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
519 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
520 function done(e) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
521 clearTimeout(going); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
522 var cur = posFromMouse(e); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
523 if (cur) doSelect(cur); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
524 e_preventDefault(e); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
525 focusInput(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
526 updateInput = true; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
527 move(); up(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
528 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
529 var move = connect(document, "mousemove", operation(function(e) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
530 clearTimeout(going); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
531 e_preventDefault(e); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
532 if (!ie && !e_button(e)) done(e); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
533 else extend(e); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
534 }), true); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
535 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
|
536 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
537 function onDoubleClick(e) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
538 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
|
539 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
|
540 e_preventDefault(e); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
541 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
542 function onDrop(e) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
543 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
|
544 e_preventDefault(e); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
545 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
|
546 if (!pos || options.readOnly) return; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
547 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
|
548 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
|
549 var loadFile = function(file, i) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
550 var reader = new FileReader; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
551 reader.onload = function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
552 text[i] = reader.result; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
553 if (++read == n) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
554 pos = clipPos(pos); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
555 operation(function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
556 var end = replaceRange(text.join(""), pos, pos); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
557 setSelectionUser(pos, end); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
558 })(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
559 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
560 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
561 reader.readAsText(file); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
562 }; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
563 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
|
564 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
565 // 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
|
566 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
|
567 try { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
568 var text = e.dataTransfer.getData("Text"); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
569 if (text) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
570 compoundChange(function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
571 var curFrom = sel.from, curTo = sel.to; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
572 setSelectionUser(pos, pos); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
573 if (draggingText) replaceRange("", curFrom, curTo); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
574 replaceSelection(text); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
575 focusInput(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
576 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
577 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
578 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
579 catch(e){} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
580 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
581 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
582 function onDragStart(e) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
583 var txt = getSelection(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
584 e.dataTransfer.setData("Text", txt); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
585 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
586 // 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
|
587 if (e.dataTransfer.setDragImage) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
588 e.dataTransfer.setDragImage(elt('img'), 0, 0); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
589 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
590 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
591 function doHandleBinding(bound, dropShift) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
592 if (typeof bound == "string") { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
593 bound = commands[bound]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
594 if (!bound) return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
595 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
596 var prevShift = shiftSelecting; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
597 try { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
598 if (options.readOnly) suppressEdits = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
599 if (dropShift) shiftSelecting = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
600 bound(instance); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
601 } catch(e) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
602 if (e != Pass) throw e; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
603 return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
604 } finally { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
605 shiftSelecting = prevShift; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
606 suppressEdits = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
607 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
608 return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
609 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
610 var maybeTransition; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
611 function handleKeyBinding(e) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
612 // Handle auto keymap transitions |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
613 var startMap = getKeyMap(options.keyMap), next = startMap.auto; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
614 clearTimeout(maybeTransition); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
615 if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
616 if (getKeyMap(options.keyMap) == startMap) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
617 options.keyMap = (next.call ? next.call(null, instance) : next); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
618 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
619 }, 50); |
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 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
|
622 var flipCtrlCmd = opera && mac; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
623 if (name == null || e.altGraphKey) return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
624 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
|
625 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
|
626 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
|
627 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
628 var stopped = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
629 function stop() { stopped = true; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
630 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
631 if (e_prop(e, "shiftKey")) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
632 handled = lookupKey("Shift-" + name, options.extraKeys, options.keyMap, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
633 function(b) {return doHandleBinding(b, true);}, stop) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
634 || lookupKey(name, options.extraKeys, options.keyMap, function(b) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
635 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
|
636 }, stop); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
637 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
638 handled = lookupKey(name, options.extraKeys, options.keyMap, doHandleBinding, stop); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
639 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
640 if (stopped) handled = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
641 if (handled) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
642 e_preventDefault(e); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
643 restartBlink(); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
644 if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
645 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
646 return handled; |
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 function handleCharBinding(e, ch) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
649 var handled = lookupKey("'" + ch + "'", options.extraKeys, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
650 options.keyMap, function(b) { return doHandleBinding(b, true); }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
651 if (handled) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
652 e_preventDefault(e); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
653 restartBlink(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
654 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
655 return handled; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
656 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
657 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
658 var lastStoppedKey = null; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
659 function onKeyDown(e) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
660 if (!focused) onFocus(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
661 if (ie && e.keyCode == 27) { e.returnValue = false; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
662 if (pollingFast) { if (readInput()) pollingFast = false; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
663 if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
664 var code = e_prop(e, "keyCode"); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
665 // IE does strange things with escape. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
666 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
|
667 // First give onKeyEvent option a chance to handle this. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
668 var handled = handleKeyBinding(e); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
669 if (opera) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
670 lastStoppedKey = handled ? code : null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
671 // 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
|
672 if (!handled && code == 88 && e_prop(e, mac ? "metaKey" : "ctrlKey")) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
673 replaceSelection(""); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
674 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
675 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
676 function onKeyPress(e) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
677 if (pollingFast) readInput(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
678 if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
679 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
|
680 if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
681 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
|
682 var ch = String.fromCharCode(charCode == null ? keyCode : charCode); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
683 if (options.electricChars && mode.electricChars && options.smartIndent && !options.readOnly) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
684 if (mode.electricChars.indexOf(ch) > -1) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
685 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
|
686 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
687 if (handleCharBinding(e, ch)) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
688 fastPoll(); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
689 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
690 function onKeyUp(e) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
691 if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
692 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
|
693 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
694 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
695 function onFocus() { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
696 if (options.readOnly == "nocursor") return; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
697 if (!focused) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
698 if (options.onFocus) options.onFocus(instance); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
699 focused = true; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
700 if (scroller.className.search(/\bCodeMirror-focused\b/) == -1) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
701 scroller.className += " CodeMirror-focused"; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
702 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
703 slowPoll(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
704 restartBlink(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
705 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
706 function onBlur() { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
707 if (focused) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
708 if (options.onBlur) options.onBlur(instance); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
709 focused = false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
710 if (bracketHighlighted) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
711 operation(function(){ |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
712 if (bracketHighlighted) { bracketHighlighted(); bracketHighlighted = null; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
713 })(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
714 scroller.className = scroller.className.replace(" CodeMirror-focused", ""); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
715 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
716 clearInterval(blinker); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
717 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
|
718 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
719 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
720 // 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
|
721 // Afterwards, set the selection to selFrom, selTo. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
722 function updateLines(from, to, newText, selFrom, selTo) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
723 if (suppressEdits) return; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
724 var old = []; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
725 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
|
726 old.push(newHL(line.text, line.markedSpans)); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
727 }); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
728 if (history) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
729 history.addChange(from.line, newText.length, old); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
730 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
|
731 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
732 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
|
733 updateLinesNoUndo(from, to, lines, selFrom, selTo); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
734 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
735 function unredoHelper(from, to) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
736 if (!from.length) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
737 var set = from.pop(), out = []; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
738 for (var i = set.length - 1; i >= 0; i -= 1) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
739 var change = set[i]; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
740 var replaced = [], end = change.start + change.added; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 change.old, pos, pos); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
747 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
748 updateInput = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
749 to.push(out); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
750 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
751 function undo() {unredoHelper(history.done, history.undone);} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
752 function redo() {unredoHelper(history.undone, history.done);} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
753 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
754 function updateLinesNoUndo(from, to, lines, selFrom, selTo) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
755 if (suppressEdits) return; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
756 var recomputeMaxLength = false, maxLineLength = maxLine.text.length; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
757 if (!options.lineWrapping) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
758 doc.iter(from.line, to.line + 1, function(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
759 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
|
760 }); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
761 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
|
762 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
763 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
|
764 var lastHL = lst(lines); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
765 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
766 // First adjust the line structure |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
767 if (from.ch == 0 && to.ch == 0 && hlText(lastHL) == "") { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
768 // This is a whole-line replace. Treated specially to make |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
769 // sure line objects move the way they are supposed to. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
770 var added = [], prevLine = null; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
771 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
|
772 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
|
773 lastLine.update(lastLine.text, hlSpans(lastHL)); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
774 if (nlines) doc.remove(from.line, nlines, callbacks); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
775 if (added.length) doc.insert(from.line, added); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
776 } else if (firstLine == lastLine) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
777 if (lines.length == 1) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
778 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
|
779 } else { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
780 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
|
781 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
|
782 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
|
783 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
|
784 doc.insert(from.line + 1, added); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
785 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
786 } else if (lines.length == 1) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
787 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
|
788 doc.remove(from.line + 1, nlines, callbacks); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
789 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
790 var added = []; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 doc.insert(from.line + 1, added); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
797 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
798 if (options.lineWrapping) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
799 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
|
800 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
|
801 if (line.hidden) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
802 var guess = Math.ceil(line.text.length / perLine) || 1; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
803 if (guess != line.height) updateLineHeight(line, guess); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
804 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
805 } else { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
806 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
|
807 var l = line.text; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
808 if (!line.hidden && l.length > maxLineLength) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
809 maxLine = line; maxLineLength = l.length; maxLineChanged = true; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
810 recomputeMaxLength = false; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
811 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
812 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
813 if (recomputeMaxLength) updateMaxLine = true; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
814 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
815 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
816 // Adjust frontier, schedule worker |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
817 frontier = Math.min(frontier, from.line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
818 startWorker(400); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
819 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
820 var lendiff = lines.length - nlines - 1; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
821 // 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
|
822 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
|
823 if (options.onChange) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
824 // 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
|
825 // the change event handler expects |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
826 for (var i = 0; i < lines.length; ++i) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
827 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
|
828 var changeObj = {from: from, to: to, text: lines}; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
829 if (textChanged) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
830 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
|
831 cur.next = changeObj; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
832 } else textChanged = changeObj; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
833 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
834 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
835 // Update the selection |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
836 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
|
837 setSelection(clipPos(selFrom), clipPos(selTo), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
838 updateLine(sel.from.line), updateLine(sel.to.line)); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
839 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
840 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
841 function needsScrollbar() { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
842 var realHeight = doc.height * textHeight() + 2 * paddingTop(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
843 return realHeight * .99 > scroller.offsetHeight ? realHeight : false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
844 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
845 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
846 function updateVerticalScroll(scrollTop) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
847 var scrollHeight = needsScrollbar(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
848 scrollbar.style.display = scrollHeight ? "block" : "none"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
849 if (scrollHeight) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
850 scrollbarInner.style.height = sizer.style.minHeight = scrollHeight + "px"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
851 scrollbar.style.height = scroller.clientHeight + "px"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
852 if (scrollTop != null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
853 scrollbar.scrollTop = scroller.scrollTop = scrollTop; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
854 // '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
|
855 // 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
|
856 // reported its scrollTop (and looked) as expected, but |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
857 // *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
|
858 // 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
|
859 // bottom). |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
860 if (webkit) setTimeout(function() { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
861 if (scrollbar.scrollTop != scrollTop) return; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
862 scrollbar.scrollTop = scrollTop + (scrollTop ? -1 : 1); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
863 scrollbar.scrollTop = scrollTop; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
864 }, 0); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
865 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
866 } else { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
867 sizer.style.minHeight = ""; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
868 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
869 // 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
|
870 mover.style.top = displayOffset * textHeight() + "px"; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
871 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
872 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
873 function computeMaxLength() { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
874 maxLine = getLine(0); maxLineChanged = true; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
875 var maxLineLength = maxLine.text.length; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
876 doc.iter(1, doc.size, function(line) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
877 var l = line.text; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
878 if (!line.hidden && l.length > maxLineLength) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
879 maxLineLength = l.length; maxLine = line; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
880 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
881 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
882 updateMaxLine = false; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
883 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
884 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
885 function replaceRange(code, from, to) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
886 from = clipPos(from); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
887 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
|
888 code = splitLines(code); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
889 function adjustPos(pos) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
890 if (posLess(pos, from)) return pos; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
891 if (!posLess(to, pos)) return end; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
892 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
|
893 var ch = pos.ch; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
894 if (pos.line == to.line) |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
895 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
|
896 return {line: line, ch: ch}; |
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 var end; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
899 replaceRange1(code, from, to, function(end1) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
900 end = end1; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
901 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
|
902 }); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
903 return end; |
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 replaceSelection(code, collapse) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
906 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
|
907 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
|
908 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
|
909 else return {from: sel.from, to: end}; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
910 }); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
911 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
912 function replaceRange1(code, from, to, computeSel) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
913 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
|
914 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
|
915 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
|
916 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
917 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
918 function getRange(from, to, lineSep) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
919 var l1 = from.line, l2 = to.line; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
920 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
|
921 var code = [getLine(l1).text.slice(from.ch)]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
922 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
|
923 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
|
924 return code.join(lineSep || "\n"); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
925 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
926 function getSelection(lineSep) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
927 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
|
928 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
929 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
930 function slowPoll() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
931 if (pollingFast) return; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
932 poll.set(options.pollInterval, function() { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
933 readInput(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
934 if (focused) slowPoll(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
935 }); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
936 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
937 function fastPoll() { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
938 var missed = false; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
939 pollingFast = true; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
940 function p() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
941 var changed = readInput(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
942 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
|
943 else {pollingFast = false; slowPoll();} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
944 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
945 poll.set(20, p); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
946 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
947 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
948 // 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
|
949 // 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
|
950 // compared to the previous content instead. (Modern browsers have |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
951 // 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
|
952 // supported or compatible enough yet to rely on.) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
953 var prevInput = ""; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
954 function readInput() { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
955 if (!focused || hasSelection(input) || options.readOnly) return false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
956 var text = input.value; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
957 if (text == prevInput) return false; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
958 if (!nestedOperation) startOperation(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
959 shiftSelecting = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
960 var same = 0, l = Math.min(prevInput.length, text.length); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
961 while (same < l && prevInput[same] == text[same]) ++same; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
962 if (same < prevInput.length) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
963 sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)}; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
964 else if (overwrite && posEq(sel.from, sel.to) && !pasteIncoming) |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
965 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
|
966 replaceSelection(text.slice(same), "end"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
967 if (text.length > 1000) { input.value = prevInput = ""; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
968 else prevInput = text; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
969 if (!nestedOperation) endOperation(); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
970 pasteIncoming = false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
971 return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
972 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
973 function resetInput(user) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
974 if (!posEq(sel.from, sel.to)) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
975 prevInput = ""; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
976 input.value = getSelection(); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
977 if (focused) selectInput(input); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
978 } else if (user) prevInput = input.value = ""; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
979 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
980 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
981 function focusInput() { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
982 if (options.readOnly != "nocursor") input.focus(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
983 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
984 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
985 function scrollCursorIntoView() { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
986 var coords = calculateCursorCoords(); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
987 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
|
988 if (!focused) return; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
989 var box = sizer.getBoundingClientRect(), doScroll = null; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
990 if (coords.y + box.top < 0) doScroll = true; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
991 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
|
992 if (doScroll != null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
993 var hidden = cursor.style.display == "none"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
994 if (hidden) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
995 cursor.style.display = ""; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
996 cursor.style.left = coords.x + "px"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
997 cursor.style.top = (coords.y - displayOffset) + "px"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
998 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
999 cursor.scrollIntoView(doScroll); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1000 if (hidden) cursor.style.display = "none"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1001 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1002 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1003 function calculateCursorCoords() { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1004 var cursor = localCoords(sel.inverted ? sel.from : sel.to); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1005 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
|
1006 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
|
1007 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1008 function scrollIntoView(x1, y1, x2, y2) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1009 var scrollPos = calculateScrollPos(x1, y1, x2, y2); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1010 if (scrollPos.scrollLeft != null) {scroller.scrollLeft = scrollPos.scrollLeft;} |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1011 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
|
1012 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1013 function calculateScrollPos(x1, y1, x2, y2) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1014 var pl = paddingLeft(), pt = paddingTop(); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1015 y1 += pt; y2 += pt; x1 += pl; x2 += pl; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1016 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
|
1017 var docBottom = needsScrollbar() || Infinity; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1018 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
|
1019 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
|
1020 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
|
1021 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1022 var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1023 var gutterw = options.fixedGutter ? gutter.clientWidth : 0; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1024 var atLeft = x1 < gutterw + pl + 10; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1025 if (x1 < screenleft + gutterw || atLeft) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1026 if (atLeft) x1 = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1027 result.scrollLeft = Math.max(0, x1 - 10 - gutterw); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1028 } else if (x2 > screenw + screenleft - 3) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1029 result.scrollLeft = x2 + 10 - screenw; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1030 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1031 return result; |
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 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1034 function visibleLines(scrollTop) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1035 var lh = textHeight(), top = (scrollTop != null ? scrollTop : scrollbar.scrollTop) - paddingTop(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1036 var fromHeight = Math.max(0, Math.floor(top / lh)); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1037 var toHeight = Math.ceil((top + scroller.clientHeight) / lh); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1038 return {from: lineAtHeight(doc, fromHeight), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1039 to: lineAtHeight(doc, toHeight)}; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1040 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1041 // 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
|
1042 // 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
|
1043 // updates. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1044 function updateDisplay(changes, suppressCallback, scrollTop) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1045 if (!scroller.clientWidth) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1046 showingFrom = showingTo = displayOffset = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1047 return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1048 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1049 // Compute the new visible window |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1050 // If scrollTop is specified, use that to determine which lines |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1051 // to render instead of the current scrollbar position. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1052 var visible = visibleLines(scrollTop); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1053 // 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
|
1054 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
|
1055 updateVerticalScroll(scrollTop); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1056 return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1057 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1058 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
|
1059 if (showingFrom < from && from - showingFrom < 20) from = showingFrom; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1060 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
|
1061 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1062 // Create a range of theoretically intact lines, and punch holes |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1063 // in that using the change info. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1064 var intact = changes === true ? [] : |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1065 computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1066 // Clip off the parts that won't be visible |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1067 var intactLines = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1068 for (var i = 0; i < intact.length; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1069 var range = intact[i]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1070 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
|
1071 if (range.to > to) range.to = to; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1072 if (range.from >= range.to) intact.splice(i--, 1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1073 else intactLines += range.to - range.from; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1074 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1075 if (intactLines == to - from && from == showingFrom && to == showingTo) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1076 updateVerticalScroll(scrollTop); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1077 return; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1078 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1079 intact.sort(function(a, b) {return a.domStart - b.domStart;}); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1080 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1081 var th = textHeight(), gutterDisplay = gutter.style.display; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1082 lineDiv.style.display = "none"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1083 patchDisplay(from, to, intact); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1084 lineDiv.style.display = gutter.style.display = ""; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1085 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1086 var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1087 // 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
|
1088 // resized or the font size changes. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1089 if (different) lastSizeC = scroller.clientHeight + th; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1090 if (from != showingFrom || to != showingTo && options.onViewportChange) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1091 setTimeout(function(){ |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1092 if (options.onViewportChange) options.onViewportChange(instance, from, to); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1093 }); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1094 showingFrom = from; showingTo = to; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1095 displayOffset = heightAtLine(doc, from); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1096 startWorker(100); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1097 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1098 // 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
|
1099 // only assertion in the whole file. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1100 if (lineDiv.childNodes.length != showingTo - showingFrom) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1101 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
|
1102 " nodes=" + lineDiv.childNodes.length); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1103 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1104 function checkHeights() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1105 var curNode = lineDiv.firstChild, heightChanged = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1106 doc.iter(showingFrom, showingTo, function(line) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1107 // 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
|
1108 // 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
|
1109 // 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
|
1110 if (!curNode) return; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1111 if (!line.hidden) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1112 var height = Math.round(curNode.offsetHeight / th) || 1; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1113 if (line.height != height) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1114 updateLineHeight(line, height); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1115 gutterDirty = heightChanged = true; |
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 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1118 curNode = curNode.nextSibling; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1119 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1120 return heightChanged; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1121 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1122 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1123 if (options.lineWrapping) checkHeights(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1124 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1125 gutter.style.display = gutterDisplay; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1126 if (different || gutterDirty) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1127 // 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
|
1128 updateGutter() && options.lineWrapping && checkHeights() && updateGutter(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1129 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1130 updateVerticalScroll(scrollTop); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1131 updateSelection(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1132 if (!suppressCallback && options.onUpdate) options.onUpdate(instance); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1133 return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1134 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1135 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1136 function computeIntact(intact, changes) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1137 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
|
1138 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
|
1139 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
|
1140 var range = intact[j]; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1141 if (change.to <= range.from && change.diff) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1142 intact2.push({from: range.from + diff, to: range.to + diff, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1143 domStart: range.domStart}); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1144 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
|
1145 intact2.push(range); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1146 else { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1147 if (change.from > range.from) |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1148 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
|
1149 if (change.to < range.to) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1150 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
|
1151 domStart: range.domStart + (change.to - range.from)}); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1152 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1153 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1154 intact = intact2; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1155 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1156 return intact; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1157 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1158 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1159 function patchDisplay(from, to, intact) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1160 function killNode(node) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1161 var tmp = node.nextSibling; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1162 node.parentNode.removeChild(node); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1163 return tmp; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1164 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1165 // 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
|
1166 if (!intact.length) removeChildren(lineDiv); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1167 else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1168 var domPos = 0, curNode = lineDiv.firstChild, n; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1169 for (var i = 0; i < intact.length; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1170 var cur = intact[i]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1171 while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1172 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
|
1173 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1174 while (curNode) curNode = killNode(curNode); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1175 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1176 // This pass fills in the lines that actually changed. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1177 var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1178 doc.iter(from, to, function(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1179 if (nextIntact && nextIntact.to == j) nextIntact = intact.shift(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1180 if (!nextIntact || nextIntact.from > j) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1181 if (line.hidden) var lineElement = elt("pre"); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1182 else { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1183 var lineElement = lineContent(line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1184 if (line.className) lineElement.className = line.className; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1185 // 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
|
1186 if (line.bgClassName) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1187 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
|
1188 lineElement = elt("div", [pre, lineElement], null, "position: relative"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1189 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1190 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1191 lineDiv.insertBefore(lineElement, curNode); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1192 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1193 curNode = curNode.nextSibling; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1194 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1195 ++j; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1196 }); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1197 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1198 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1199 function updateGutter() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1200 if (!options.gutter && !options.lineNumbers) return; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1201 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
|
1202 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
|
1203 var fragment = document.createDocumentFragment(), i = showingFrom, normalNode; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1204 doc.iter(showingFrom, Math.max(showingTo, showingFrom + 1), function(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1205 if (line.hidden) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1206 fragment.appendChild(elt("pre")); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1207 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1208 var marker = line.gutterMarker; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1209 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
|
1210 if (marker && marker.text) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1211 text = marker.text.replace("%N%", text != null ? text : ""); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1212 else if (text == null) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1213 text = "\u00a0"; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1214 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
|
1215 markerElement.innerHTML = text; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1216 for (var j = 1; j < line.height; ++j) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1217 markerElement.appendChild(elt("br")); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1218 markerElement.appendChild(document.createTextNode("\u00a0")); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1219 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1220 if (!marker) normalNode = i; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1221 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1222 ++i; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1223 }); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1224 gutter.style.display = "none"; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1225 removeChildrenAndAdd(gutterText, fragment); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1226 // 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
|
1227 if (normalNode != null && options.lineNumbers) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1228 var node = gutterText.childNodes[normalNode - showingFrom]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1229 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
|
1230 while (val.length + pad.length < minwidth) pad += "\u00a0"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1231 if (pad) node.insertBefore(document.createTextNode(pad), node.firstChild); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1232 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1233 gutter.style.display = ""; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1234 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
|
1235 lineSpace.style.marginLeft = gutter.offsetWidth + "px"; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1236 gutterDirty = false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1237 return resized; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1238 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1239 function updateSelection() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1240 var collapsed = posEq(sel.from, sel.to); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1241 var fromPos = localCoords(sel.from, true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1242 var toPos = collapsed ? fromPos : localCoords(sel.to, true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1243 var headPos = sel.inverted ? fromPos : toPos, th = textHeight(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1244 var wrapOff = eltOffset(wrapper), lineOff = eltOffset(lineDiv); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1245 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
|
1246 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
|
1247 if (collapsed) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1248 cursor.style.top = headPos.y + "px"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1249 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
|
1250 cursor.style.display = ""; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1251 selectionDiv.style.display = "none"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1252 } else { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1253 var sameLine = fromPos.y == toPos.y, fragment = document.createDocumentFragment(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1254 var clientWidth = lineSpace.clientWidth || lineSpace.offsetWidth; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1255 var clientHeight = lineSpace.clientHeight || lineSpace.offsetHeight; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1256 var add = function(left, top, right, height) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1257 var rstyle = quirksMode ? "width: " + (!right ? clientWidth : clientWidth - right - left) + "px" |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1258 : "right: " + right + "px"; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1259 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
|
1260 "px; top: " + top + "px; " + rstyle + "; height: " + height + "px")); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1261 }; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1262 if (sel.from.ch && fromPos.y >= 0) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1263 var right = sameLine ? clientWidth - toPos.x : 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1264 add(fromPos.x, fromPos.y, right, th); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1265 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1266 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
|
1267 var middleHeight = Math.min(toPos.y, clientHeight) - middleStart; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1268 if (middleHeight > 0.2 * th) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1269 add(0, middleStart, 0, middleHeight); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1270 if ((!sameLine || !sel.from.ch) && toPos.y < clientHeight - .5 * th) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1271 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
|
1272 removeChildrenAndAdd(selectionDiv, fragment); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1273 cursor.style.display = "none"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1274 selectionDiv.style.display = ""; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1275 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1276 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1277 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1278 function setShift(val) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1279 if (val) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1280 else shiftSelecting = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1281 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1282 function setSelectionUser(from, to) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1283 var sh = shiftSelecting && clipPos(shiftSelecting); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1284 if (sh) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1285 if (posLess(sh, from)) from = sh; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1286 else if (posLess(to, sh)) to = sh; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1287 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1288 setSelection(from, to); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1289 userSelChange = true; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1290 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1291 // 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
|
1292 // 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
|
1293 // numbers before the update. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1294 function setSelection(from, to, oldFrom, oldTo) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1295 goalColumn = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1296 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
|
1297 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
|
1298 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
|
1299 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1300 // Skip over hidden lines. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1301 if (from.line != oldFrom) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1302 var from1 = skipHidden(from, oldFrom, sel.from.ch); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1303 // 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
|
1304 if (!from1) setLineHidden(from.line, false); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1305 else from = from1; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1306 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1307 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
|
1308 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1309 if (posEq(from, to)) sel.inverted = false; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1310 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
|
1311 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
|
1312 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1313 if (options.autoClearEmptyLines && posEq(sel.from, sel.to)) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1314 var head = sel.inverted ? from : to; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1315 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
|
1316 var oldLine = getLine(sel.from.line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1317 if (/^\s+$/.test(oldLine.text)) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1318 setTimeout(operation(function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1319 if (oldLine.parent && /^\s+$/.test(oldLine.text)) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1320 var no = lineNo(oldLine); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1321 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
|
1322 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1323 }, 10)); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1324 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1325 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1326 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1327 sel.from = from; sel.to = to; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1328 selectionChanged = true; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1329 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1330 function skipHidden(pos, oldLine, oldCh) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1331 function getNonHidden(dir) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1332 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
|
1333 while (lNo != end) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1334 var line = getLine(lNo); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1335 if (!line.hidden) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1336 var ch = pos.ch; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1337 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
|
1338 return {line: lNo, ch: ch}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1339 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1340 lNo += dir; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1341 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1342 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1343 var line = getLine(pos.line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1344 var toEnd = pos.ch == line.text.length && pos.ch != oldCh; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1345 if (!line.hidden) return pos; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1346 if (pos.line >= oldLine) return getNonHidden(1) || getNonHidden(-1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1347 else return getNonHidden(-1) || getNonHidden(1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1348 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1349 function setCursor(line, ch, user) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1350 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
|
1351 (user ? setSelectionUser : setSelection)(pos, pos); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1352 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1353 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1354 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
|
1355 function clipPos(pos) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1356 if (pos.line < 0) return {line: 0, ch: 0}; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1357 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
|
1358 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
|
1359 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
|
1360 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
|
1361 else return pos; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1362 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1363 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1364 function findPosH(dir, unit) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1365 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
|
1366 var lineObj = getLine(line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1367 function findNextLine() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1368 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
|
1369 var lo = getLine(l); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1370 if (!lo.hidden) { line = l; lineObj = lo; 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 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1373 function moveOnce(boundToLine) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1374 if (ch == (dir < 0 ? 0 : lineObj.text.length)) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1375 if (!boundToLine && findNextLine()) ch = dir < 0 ? lineObj.text.length : 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1376 else return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1377 } else ch += dir; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1378 return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1379 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1380 if (unit == "char") moveOnce(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1381 else if (unit == "column") moveOnce(true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1382 else if (unit == "word") { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1383 var sawWord = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1384 for (;;) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1385 if (dir < 0) if (!moveOnce()) break; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1386 if (isWordChar(lineObj.text.charAt(ch))) sawWord = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1387 else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1388 if (dir > 0) if (!moveOnce()) break; |
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 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1391 return {line: line, ch: ch}; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1392 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1393 function moveH(dir, unit) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1394 var pos = dir < 0 ? sel.from : sel.to; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1395 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
|
1396 setCursor(pos.line, pos.ch, true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1397 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1398 function deleteH(dir, unit) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1399 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
|
1400 else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1401 else replaceRange("", sel.from, findPosH(dir, unit)); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1402 userSelChange = true; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1403 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1404 function moveV(dir, unit) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1405 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
|
1406 if (goalColumn != null) pos.x = goalColumn; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1407 if (unit == "page") { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1408 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
|
1409 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
|
1410 } else if (unit == "line") { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1411 var th = textHeight(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1412 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
|
1413 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1414 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
|
1415 setCursor(target.line, target.ch, true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1416 goalColumn = pos.x; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1417 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1418 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1419 function findWordAt(pos) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1420 var line = getLine(pos.line).text; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1421 var start = pos.ch, end = pos.ch; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1422 if (line) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1423 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
|
1424 var startChar = line.charAt(start); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1425 var check = isWordChar(startChar) ? isWordChar : |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1426 /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} : |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1427 function(ch) {return !/\s/.test(ch) && isWordChar(ch);}; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1428 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
|
1429 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
|
1430 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1431 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
|
1432 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1433 function selectLine(line) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1434 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
|
1435 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1436 function indentSelected(mode) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1437 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
|
1438 var e = sel.to.line - (sel.to.ch ? 0 : 1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1439 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
|
1440 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1441 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1442 function indentLine(n, how) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1443 if (!how) how = "add"; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1444 if (how == "smart") { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1445 if (!mode.indent) how = "prev"; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1446 else var state = getStateBefore(n); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1447 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1448 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1449 var line = getLine(n), curSpace = line.indentation(options.tabSize), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1450 curSpaceString = line.text.match(/^\s*/)[0], indentation; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1451 if (how == "smart") { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1452 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
|
1453 if (indentation == Pass) how = "prev"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1454 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1455 if (how == "prev") { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1456 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
|
1457 else indentation = 0; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1458 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1459 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
|
1460 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
|
1461 indentation = Math.max(0, indentation); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1462 var diff = indentation - curSpace; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1463 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1464 var indentString = "", pos = 0; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1465 if (options.indentWithTabs) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1466 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
|
1467 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
|
1468 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1469 if (indentString != curSpaceString) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1470 replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length}); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1471 line.stateAfter = null; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1472 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1473 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1474 function loadMode() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1475 mode = CodeMirror.getMode(options, options.mode); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1476 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
|
1477 frontier = 0; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1478 startWorker(100); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1479 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1480 function gutterChanged() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1481 var visible = options.gutter || options.lineNumbers; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1482 gutter.style.display = visible ? "" : "none"; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1483 if (visible) gutterDirty = true; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1484 else lineDiv.parentNode.style.marginLeft = 0; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1485 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1486 function wrappingChanged(from, to) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1487 if (options.lineWrapping) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1488 wrapper.className += " CodeMirror-wrap"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1489 var perLine = scroller.clientWidth / charWidth() - 3; |
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.hidden) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1492 var guess = Math.ceil(line.text.length / perLine) || 1; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1493 if (guess != 1) updateLineHeight(line, guess); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1494 }); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1495 lineSpace.style.minWidth = widthForcer.style.left = ""; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1496 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1497 wrapper.className = wrapper.className.replace(" CodeMirror-wrap", ""); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1498 computeMaxLength(); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1499 doc.iter(0, doc.size, function(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1500 if (line.height != 1 && !line.hidden) updateLineHeight(line, 1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1501 }); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1502 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1503 changes.push({from: 0, to: doc.size}); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1504 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1505 function themeChanged() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1506 scroller.className = scroller.className.replace(/\s*cm-s-\S+/g, "") + |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1507 options.theme.replace(/(^|\s)\s*/g, " cm-s-"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1508 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1509 function keyMapChanged() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1510 var style = keyMap[options.keyMap].style; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1511 wrapper.className = wrapper.className.replace(/\s*cm-keymap-\S+/g, "") + |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1512 (style ? " cm-keymap-" + style : ""); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1513 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1514 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1515 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
|
1516 TextMarker.prototype.clear = operation(function() { |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1517 var min, max; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1518 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
|
1519 var line = this.lines[i]; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1520 var span = getMarkedSpanFor(line.markedSpans, this); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1521 if (span.from != null) min = lineNo(line); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1522 if (span.to != null) max = lineNo(line); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1523 line.markedSpans = removeMarkedSpan(line.markedSpans, span); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1524 } |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1525 if (min != null) changes.push({from: min, to: max + 1}); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1526 this.lines.length = 0; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1527 this.explicitlyCleared = true; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1528 }); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1529 TextMarker.prototype.find = function() { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1530 var from, to; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1531 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
|
1532 var line = this.lines[i]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1533 var span = getMarkedSpanFor(line.markedSpans, this); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1534 if (span.from != null || span.to != null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1535 var found = lineNo(line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1536 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
|
1537 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
|
1538 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1539 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1540 if (this.type == "bookmark") return from; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1541 return from && {from: from, to: to}; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1542 }; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1543 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1544 function markText(from, to, className, options) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1545 from = clipPos(from); to = clipPos(to); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1546 var marker = new TextMarker("range", className); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1547 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
|
1548 marker[opt] = options[opt]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1549 var curLine = from.line; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1550 doc.iter(curLine, to.line + 1, function(line) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1551 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
|
1552 to: curLine == to.line ? to.ch : null, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1553 marker: marker}; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1554 line.markedSpans = (line.markedSpans || []).concat([span]); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1555 marker.lines.push(line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1556 ++curLine; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1557 }); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1558 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
|
1559 return marker; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1560 } |
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 function setBookmark(pos) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1563 pos = clipPos(pos); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1564 var marker = new TextMarker("bookmark"), line = getLine(pos.line); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1565 history.addChange(pos.line, 1, [newHL(line.text, line.markedSpans)], true); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1566 var span = {from: pos.ch, to: pos.ch, marker: marker}; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1567 line.markedSpans = (line.markedSpans || []).concat([span]); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1568 marker.lines.push(line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1569 return marker; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1570 } |
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 function findMarksAt(pos) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1573 pos = clipPos(pos); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1574 var markers = [], spans = getLine(pos.line).markedSpans; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1575 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
|
1576 var span = spans[i]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1577 if ((span.from == null || span.from <= pos.ch) && |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1578 (span.to == null || span.to >= pos.ch)) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1579 markers.push(span.marker); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1580 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1581 return markers; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1582 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1583 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1584 function addGutterMarker(line, text, className) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1585 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
|
1586 line.gutterMarker = {text: text, style: className}; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1587 gutterDirty = true; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1588 return line; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1589 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1590 function removeGutterMarker(line) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1591 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
|
1592 line.gutterMarker = null; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1593 gutterDirty = true; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1594 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1595 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1596 function changeLine(handle, op) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1597 var no = handle, line = handle; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1598 if (typeof handle == "number") line = getLine(clipLine(handle)); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1599 else no = lineNo(handle); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1600 if (no == null) return null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1601 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
|
1602 else return null; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1603 return line; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1604 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1605 function setLineClass(handle, className, bgClassName) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1606 return changeLine(handle, function(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1607 if (line.className != className || line.bgClassName != bgClassName) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1608 line.className = className; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1609 line.bgClassName = bgClassName; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1610 return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1611 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1612 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1613 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1614 function setLineHidden(handle, hidden) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1615 return changeLine(handle, function(line, no) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1616 if (line.hidden != hidden) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1617 line.hidden = hidden; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1618 if (!options.lineWrapping) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1619 if (hidden && line.text.length == maxLine.text.length) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1620 updateMaxLine = true; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1621 } 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
|
1622 maxLine = line; updateMaxLine = false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1623 } |
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 updateLineHeight(line, hidden ? 0 : 1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1626 var fline = sel.from.line, tline = sel.to.line; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1627 if (hidden && (fline == no || tline == no)) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1628 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
|
1629 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
|
1630 // 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
|
1631 if (!to) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1632 setSelection(from, to); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1633 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1634 return (gutterDirty = true); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1635 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1636 }); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1637 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1638 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1639 function lineInfo(line) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1640 if (typeof line == "number") { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1641 if (!isLine(line)) return null; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1642 var n = line; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1643 line = getLine(line); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1644 if (!line) return null; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1645 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1646 var n = lineNo(line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1647 if (n == null) return null; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1648 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1649 var marker = line.gutterMarker; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1650 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
|
1651 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
|
1652 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1653 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1654 function measureLine(line, ch) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1655 if (ch == 0) return {top: 0, left: 0}; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1656 var pre = lineContent(line, ch); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1657 removeChildrenAndAdd(measure, pre); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1658 var anchor = pre.anchor; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1659 var top = anchor.offsetTop, left = anchor.offsetLeft; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1660 // 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
|
1661 if (ie && top == 0 && left == 0) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1662 var backup = elt("span", "x"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1663 anchor.parentNode.insertBefore(backup, anchor.nextSibling); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1664 top = backup.offsetTop; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1665 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1666 return {top: top, left: left}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1667 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1668 function localCoords(pos, inLineWrap) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1669 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
|
1670 if (pos.ch == 0) x = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1671 else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1672 var sp = measureLine(getLine(pos.line), pos.ch); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1673 x = sp.left; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1674 if (options.lineWrapping) y += Math.max(0, sp.top); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1675 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1676 return {x: x, y: y, yBot: y + lh}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1677 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1678 // Coords must be lineSpace-local |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1679 function coordsChar(x, y) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1680 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
|
1681 if (heightPos < 0) return {line: 0, ch: 0}; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1682 var lineNo = lineAtHeight(doc, heightPos); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1683 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
|
1684 var lineObj = getLine(lineNo), text = lineObj.text; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1685 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
|
1686 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
|
1687 var wrongLine = false; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1688 function getX(len) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1689 var sp = measureLine(lineObj, len); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1690 if (tw) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1691 var off = Math.round(sp.top / th); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1692 wrongLine = off != innerOff; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1693 return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1694 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1695 return sp.left; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1696 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1697 var from = 0, fromX = 0, to = text.length, toX; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1698 // Guess a suitable upper bound for our search. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1699 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
|
1700 for (;;) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1701 var estX = getX(estimated); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1702 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
|
1703 else {toX = estX; to = estimated; break;} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1704 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1705 if (x > toX) return {line: lineNo, ch: to}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1706 // Try to guess a suitable lower bound as well. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1707 estimated = Math.floor(to * 0.8); estX = getX(estimated); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1708 if (estX < x) {from = estimated; fromX = estX;} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1709 // Do a binary search between these bounds. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1710 for (;;) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1711 if (to - from <= 1) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1712 var after = x - fromX < toX - x; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1713 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
|
1714 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1715 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
|
1716 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
|
1717 else {from = middle; fromX = middleX;} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1718 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1719 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1720 function pageCoords(pos) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1721 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
|
1722 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
|
1723 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1724 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1725 var cachedHeight, cachedHeightFor, measurePre; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1726 function textHeight() { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1727 if (measurePre == null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1728 measurePre = elt("pre"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1729 for (var i = 0; i < 49; ++i) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1730 measurePre.appendChild(document.createTextNode("x")); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1731 measurePre.appendChild(elt("br")); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1732 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1733 measurePre.appendChild(document.createTextNode("x")); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1734 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1735 var offsetHeight = lineDiv.clientHeight; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1736 if (offsetHeight == cachedHeightFor) return cachedHeight; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1737 cachedHeightFor = offsetHeight; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1738 removeChildrenAndAdd(measure, measurePre.cloneNode(true)); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1739 cachedHeight = measure.firstChild.offsetHeight / 50 || 1; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1740 removeChildren(measure); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1741 return cachedHeight; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1742 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1743 var cachedWidth, cachedWidthFor = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1744 function charWidth() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1745 if (scroller.clientWidth == cachedWidthFor) return cachedWidth; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1746 cachedWidthFor = scroller.clientWidth; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1747 var anchor = elt("span", "x"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1748 var pre = elt("pre", [anchor]); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1749 removeChildrenAndAdd(measure, pre); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1750 return (cachedWidth = anchor.offsetWidth || 10); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1751 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1752 function paddingTop() {return lineSpace.offsetTop;} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1753 function paddingLeft() {return lineSpace.offsetLeft;} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1754 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1755 function posFromMouse(e, liberal) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1756 var offW = eltOffset(scroller, true), x, y; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1757 // 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
|
1758 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
|
1759 // 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
|
1760 // 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
|
1761 // (and !liberal). |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1762 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
|
1763 return null; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1764 var offL = eltOffset(lineSpace, true); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1765 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
|
1766 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1767 var detectingSelectAll; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1768 function onContextMenu(e) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1769 var pos = posFromMouse(e), scrollPos = scrollbar.scrollTop; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1770 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
|
1771 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
|
1772 operation(setCursor)(pos.line, pos.ch); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1773 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1774 var oldCSS = input.style.cssText; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1775 inputDiv.style.position = "absolute"; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1776 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
|
1777 "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
|
1778 "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
|
1779 focusInput(); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1780 resetInput(true); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1781 // Adds "Select all" to context menu in FF |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1782 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
|
1783 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1784 function rehide() { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1785 inputDiv.style.position = "relative"; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1786 input.style.cssText = oldCSS; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1787 if (ie_lt9) scrollbar.scrollTop = scrollPos; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1788 slowPoll(); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1789 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1790 // Try to detect the user choosing select-all |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1791 if (input.selectionStart != null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1792 clearTimeout(detectingSelectAll); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1793 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
|
1794 prevInput = " "; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1795 input.selectionStart = 1; input.selectionEnd = extval.length; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1796 detectingSelectAll = setTimeout(function poll(){ |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1797 if (prevInput == " " && input.selectionStart == 0) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1798 operation(commands.selectAll)(instance); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1799 else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1800 else resetInput(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1801 }, 200); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1802 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1803 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1804 |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1805 if (gecko) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1806 e_stop(e); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1807 var mouseup = connect(window, "mouseup", function() { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1808 mouseup(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1809 setTimeout(rehide, 20); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1810 }, true); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1811 } else { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1812 setTimeout(rehide, 50); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1813 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1814 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1815 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1816 // Cursor-blinking |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1817 function restartBlink() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1818 clearInterval(blinker); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1819 var on = true; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1820 cursor.style.visibility = ""; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1821 blinker = setInterval(function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1822 cursor.style.visibility = (on = !on) ? "" : "hidden"; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1823 }, options.cursorBlinkRate); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1824 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1825 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1826 var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1827 function matchBrackets(autoclear) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1828 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
|
1829 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
|
1830 if (!match) return; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1831 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
|
1832 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
|
1833 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
|
1834 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1835 var stack = [line.text.charAt(pos)], re = /[(){}[\]]/; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1836 function scan(line, from, to) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1837 if (!line.text) return; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1838 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
|
1839 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
|
1840 var text = st[i]; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1841 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
|
1842 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
|
1843 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
|
1844 var match = matching[cur]; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1845 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
|
1846 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
|
1847 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
|
1848 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1849 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1850 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1851 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1852 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
|
1853 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
|
1854 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
|
1855 if (found) break; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1856 } |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1857 if (!found) found = {pos: null, match: false}; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1858 var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1859 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
|
1860 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
|
1861 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
|
1862 if (autoclear) setTimeout(clear, 800); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1863 else bracketHighlighted = clear; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1864 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1865 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1866 // 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
|
1867 // 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
|
1868 // 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
|
1869 // 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
|
1870 // parse correctly. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1871 function findStartLine(n) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1872 var minindent, minline; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1873 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
|
1874 if (search == 0) return 0; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1875 var line = getLine(search-1); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1876 if (line.stateAfter) return search; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1877 var indented = line.indentation(options.tabSize); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1878 if (minline == null || minindent > indented) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1879 minline = search - 1; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1880 minindent = indented; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1881 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1882 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1883 return minline; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1884 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1885 function getStateBefore(n) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1886 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
|
1887 if (!state) state = startState(mode); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1888 else state = copyState(mode, state); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1889 doc.iter(pos, n, function(line) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1890 line.process(mode, state, options.tabSize); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1891 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
|
1892 }); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1893 return state; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1894 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1895 function highlightWorker() { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1896 if (frontier >= showingTo) return; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1897 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
|
1898 var startFrontier = frontier; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1899 doc.iter(frontier, showingTo, function(line) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1900 if (frontier >= showingFrom) { // Visible |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1901 line.highlight(mode, state, options.tabSize); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1902 line.stateAfter = copyState(mode, state); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1903 } else { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1904 line.process(mode, state, options.tabSize); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1905 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
|
1906 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1907 ++frontier; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1908 if (+new Date > end) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1909 startWorker(options.workDelay); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1910 return true; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1911 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1912 }); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1913 if (showingTo > startFrontier && frontier >= showingFrom) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1914 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
|
1915 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1916 function startWorker(time) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1917 if (frontier < showingTo) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1918 highlight.set(time, highlightWorker); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1919 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1920 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1921 // 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
|
1922 // 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
|
1923 // 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
|
1924 // 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
|
1925 function startOperation() { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1926 updateInput = userSelChange = textChanged = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1927 changes = []; selectionChanged = false; callbacks = []; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1928 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1929 function endOperation() { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1930 if (updateMaxLine) computeMaxLength(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1931 if (maxLineChanged && !options.lineWrapping) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1932 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
|
1933 if (!ie_lt8) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1934 widthForcer.style.left = left + "px"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1935 lineSpace.style.minWidth = (left + cursorWidth) + "px"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1936 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1937 maxLineChanged = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1938 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1939 var newScrollPos, updated; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1940 if (selectionChanged) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1941 var coords = calculateCursorCoords(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1942 newScrollPos = calculateScrollPos(coords.x, coords.y, coords.x, coords.yBot); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1943 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1944 if (changes.length || newScrollPos && newScrollPos.scrollTop != null) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1945 updated = updateDisplay(changes, true, newScrollPos && newScrollPos.scrollTop); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1946 if (!updated) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1947 if (selectionChanged) updateSelection(); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1948 if (gutterDirty) updateGutter(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1949 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1950 if (newScrollPos) scrollCursorIntoView(); |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1951 if (selectionChanged) restartBlink(); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1952 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
1953 if (focused && (updateInput === true || (updateInput !== false && selectionChanged))) |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1954 resetInput(userSelChange); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1955 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1956 if (selectionChanged && options.matchBrackets) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1957 setTimeout(operation(function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1958 if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;} |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1959 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
|
1960 }), 20); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1961 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
|
1962 if (textChanged && options.onChange && instance) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1963 options.onChange(instance, textChanged); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1964 if (sc && options.onCursorActivity) |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1965 options.onCursorActivity(instance); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1966 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
|
1967 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
|
1968 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1969 var nestedOperation = 0; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1970 function operation(f) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1971 return function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1972 if (!nestedOperation++) startOperation(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1973 try {var result = f.apply(this, arguments);} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1974 finally {if (!--nestedOperation) endOperation();} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1975 return result; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1976 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1977 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1978 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1979 function compoundChange(f) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1980 history.startCompound(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1981 try { return f(); } finally { history.endCompound(); } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1982 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1983 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1984 for (var ext in extensions) |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1985 if (extensions.propertyIsEnumerable(ext) && |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1986 !instance.propertyIsEnumerable(ext)) |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1987 instance[ext] = extensions[ext]; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
1988 for (var i = 0; i < initHooks.length; ++i) initHooks[i](instance); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1989 return instance; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1990 } // (end of function CodeMirror) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1991 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1992 // The default configuration options. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1993 CodeMirror.defaults = { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1994 value: "", |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1995 mode: null, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
1996 theme: "default", |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1997 indentUnit: 2, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1998 indentWithTabs: false, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
1999 smartIndent: true, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2000 tabSize: 4, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2001 keyMap: "default", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2002 extraKeys: null, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2003 electricChars: true, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2004 autoClearEmptyLines: false, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2005 onKeyEvent: null, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2006 onDragEvent: null, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2007 lineWrapping: false, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2008 lineNumbers: false, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2009 gutter: false, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2010 fixedGutter: false, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2011 firstLineNumber: 1, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2012 readOnly: false, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2013 dragDrop: true, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2014 onChange: null, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2015 onCursorActivity: null, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2016 onViewportChange: null, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2017 onGutterClick: null, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2018 onUpdate: null, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2019 onFocus: null, onBlur: null, onScroll: null, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2020 matchBrackets: false, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2021 cursorBlinkRate: 530, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2022 workTime: 100, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2023 workDelay: 200, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2024 pollInterval: 100, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2025 undoDepth: 40, |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2026 tabindex: null, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2027 autofocus: null, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2028 lineNumberFormatter: function(integer) { return integer; } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2029 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2030 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2031 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
|
2032 var mac = ios || /Mac/.test(navigator.platform); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2033 var win = /Win/.test(navigator.platform); |
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 // Known modes, by name and by MIME |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2036 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
|
2037 CodeMirror.defineMode = function(name, mode) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2038 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
|
2039 if (arguments.length > 2) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2040 mode.dependencies = []; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2041 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
|
2042 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2043 modes[name] = mode; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2044 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2045 CodeMirror.defineMIME = function(mime, spec) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2046 mimeModes[mime] = spec; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2047 }; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2048 CodeMirror.resolveMode = function(spec) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2049 if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2050 spec = mimeModes[spec]; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2051 else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2052 return CodeMirror.resolveMode("application/xml"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2053 if (typeof spec == "string") return {name: spec}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2054 else return spec || {name: "null"}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2055 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2056 CodeMirror.getMode = function(options, spec) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2057 var spec = CodeMirror.resolveMode(spec); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2058 var mfactory = modes[spec.name]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2059 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
|
2060 var modeObj = mfactory(options, spec); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2061 if (modeExtensions.hasOwnProperty(spec.name)) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2062 var exts = modeExtensions[spec.name]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2063 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
|
2064 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2065 modeObj.name = spec.name; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2066 return modeObj; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2067 }; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2068 CodeMirror.listModes = function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2069 var list = []; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2070 for (var m in modes) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2071 if (modes.propertyIsEnumerable(m)) list.push(m); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2072 return list; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2073 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2074 CodeMirror.listMIMEs = function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2075 var list = []; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2076 for (var m in mimeModes) |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2077 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
|
2078 return list; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2079 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2080 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2081 var extensions = CodeMirror.extensions = {}; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2082 CodeMirror.defineExtension = function(name, func) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2083 extensions[name] = func; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2084 }; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2085 |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2086 var initHooks = []; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2087 CodeMirror.defineInitHook = function(f) {initHooks.push(f);}; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2088 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2089 var modeExtensions = CodeMirror.modeExtensions = {}; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2090 CodeMirror.extendMode = function(mode, properties) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2091 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
|
2092 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
|
2093 exts[prop] = properties[prop]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2094 }; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2095 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2096 var commands = CodeMirror.commands = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2097 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
|
2098 killLine: function(cm) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2099 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
|
2100 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
|
2101 else cm.replaceRange("", from, sel ? to : {line: from.line}); |
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 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
|
2104 undo: function(cm) {cm.undo();}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2105 redo: function(cm) {cm.redo();}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2106 goDocStart: function(cm) {cm.setCursor(0, 0, true);}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2107 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
|
2108 goLineStart: function(cm) {cm.setCursor(cm.getCursor().line, 0, true);}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2109 goLineStartSmart: function(cm) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2110 var cur = cm.getCursor(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2111 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
|
2112 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
|
2113 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2114 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
|
2115 goLineUp: function(cm) {cm.moveV(-1, "line");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2116 goLineDown: function(cm) {cm.moveV(1, "line");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2117 goPageUp: function(cm) {cm.moveV(-1, "page");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2118 goPageDown: function(cm) {cm.moveV(1, "page");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2119 goCharLeft: function(cm) {cm.moveH(-1, "char");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2120 goCharRight: function(cm) {cm.moveH(1, "char");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2121 goColumnLeft: function(cm) {cm.moveH(-1, "column");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2122 goColumnRight: function(cm) {cm.moveH(1, "column");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2123 goWordLeft: function(cm) {cm.moveH(-1, "word");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2124 goWordRight: function(cm) {cm.moveH(1, "word");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2125 delCharLeft: function(cm) {cm.deleteH(-1, "char");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2126 delCharRight: function(cm) {cm.deleteH(1, "char");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2127 delWordLeft: function(cm) {cm.deleteH(-1, "word");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2128 delWordRight: function(cm) {cm.deleteH(1, "word");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2129 indentAuto: function(cm) {cm.indentSelection("smart");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2130 indentMore: function(cm) {cm.indentSelection("add");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2131 indentLess: function(cm) {cm.indentSelection("subtract");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2132 insertTab: function(cm) {cm.replaceSelection("\t", "end");}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2133 defaultTab: function(cm) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2134 if (cm.somethingSelected()) cm.indentSelection("add"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2135 else cm.replaceSelection("\t", "end"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2136 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2137 transposeChars: function(cm) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2138 var cur = cm.getCursor(), line = cm.getLine(cur.line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2139 if (cur.ch > 0 && cur.ch < line.length - 1) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2140 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
|
2141 {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
|
2142 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2143 newlineAndIndent: function(cm) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2144 cm.replaceSelection("\n", "end"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2145 cm.indentLine(cm.getCursor().line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2146 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2147 toggleOverwrite: function(cm) {cm.toggleOverwrite();} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2148 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2149 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2150 var keyMap = CodeMirror.keyMap = {}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2151 keyMap.basic = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2152 "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2153 "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2154 "Delete": "delCharRight", "Backspace": "delCharLeft", "Tab": "defaultTab", "Shift-Tab": "indentAuto", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2155 "Enter": "newlineAndIndent", "Insert": "toggleOverwrite" |
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 // 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
|
2158 // default. Unknown commands are simply ignored. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2159 keyMap.pcDefault = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2160 "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
|
2161 "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
|
2162 "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
|
2163 "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
|
2164 "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
|
2165 "Ctrl-[": "indentLess", "Ctrl-]": "indentMore", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2166 fallthrough: "basic" |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2167 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2168 keyMap.macDefault = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2169 "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
|
2170 "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
|
2171 "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
|
2172 "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
|
2173 "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
|
2174 "Cmd-[": "indentLess", "Cmd-]": "indentMore", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2175 fallthrough: ["basic", "emacsy"] |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2176 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2177 keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2178 keyMap.emacsy = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2179 "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
|
2180 "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd", |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2181 "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft", |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2182 "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
|
2183 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2184 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2185 function getKeyMap(val) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2186 if (typeof val == "string") return keyMap[val]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2187 else return val; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2188 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2189 function lookupKey(name, extraMap, map, handle, stop) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2190 function lookup(map) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2191 map = getKeyMap(map); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2192 var found = map[name]; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2193 if (found === false) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2194 if (stop) stop(); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2195 return true; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2196 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2197 if (found != null && handle(found)) return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2198 if (map.nofallthrough) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2199 if (stop) stop(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2200 return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2201 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2202 var fallthrough = map.fallthrough; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2203 if (fallthrough == null) return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2204 if (Object.prototype.toString.call(fallthrough) != "[object Array]") |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2205 return lookup(fallthrough); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2206 for (var i = 0, e = fallthrough.length; i < e; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2207 if (lookup(fallthrough[i])) return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2208 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2209 return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2210 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2211 if (extraMap && lookup(extraMap)) return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2212 return lookup(map); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2213 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2214 function isModifierKey(event) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2215 var name = keyNames[e_prop(event, "keyCode")]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2216 return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2217 } |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2218 CodeMirror.isModifierKey = isModifierKey; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2219 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2220 CodeMirror.fromTextArea = function(textarea, options) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2221 if (!options) options = {}; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2222 options.value = textarea.value; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2223 if (!options.tabindex && textarea.tabindex) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2224 options.tabindex = textarea.tabindex; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2225 // 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
|
2226 // autofocus and no other element is focused. |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2227 if (options.autofocus == null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2228 var hasFocus = document.body; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2229 // doc.activeElement occasionally throws on IE |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2230 try { hasFocus = document.activeElement; } catch(e) {} |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2231 options.autofocus = hasFocus == textarea || |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2232 textarea.getAttribute("autofocus") != null && hasFocus == document.body; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2233 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2234 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2235 function save() {textarea.value = instance.getValue();} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2236 if (textarea.form) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2237 // 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
|
2238 var rmSubmit = connect(textarea.form, "submit", save, true); |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2239 var realSubmit = textarea.form.submit; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2240 textarea.form.submit = function wrappedSubmit() { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2241 save(); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2242 textarea.form.submit = realSubmit; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2243 textarea.form.submit(); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2244 textarea.form.submit = wrappedSubmit; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2245 }; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2246 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2247 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2248 textarea.style.display = "none"; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2249 var instance = CodeMirror(function(node) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2250 textarea.parentNode.insertBefore(node, textarea.nextSibling); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2251 }, options); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2252 instance.save = save; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2253 instance.getTextArea = function() { return textarea; }; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2254 instance.toTextArea = function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2255 save(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2256 textarea.parentNode.removeChild(instance.getWrapperElement()); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2257 textarea.style.display = ""; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2258 if (textarea.form) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2259 rmSubmit(); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2260 if (typeof textarea.form.submit == "function") |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2261 textarea.form.submit = realSubmit; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2262 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2263 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2264 return instance; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2265 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2266 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2267 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
|
2268 var ie = /MSIE \d/.test(navigator.userAgent); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2269 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
|
2270 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
|
2271 var quirksMode = ie && document.documentMode == 5; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2272 var webkit = /WebKit\//.test(navigator.userAgent); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2273 var chrome = /Chrome\//.test(navigator.userAgent); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2274 var opera = /Opera\//.test(navigator.userAgent); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2275 var safari = /Apple Computer/.test(navigator.vendor); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2276 var khtml = /KHTML\//.test(navigator.userAgent); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2277 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
|
2278 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2279 // 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
|
2280 // sometimes need to do this. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2281 function copyState(mode, state) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2282 if (state === true) return state; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2283 if (mode.copyState) return mode.copyState(state); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2284 var nstate = {}; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2285 for (var n in state) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2286 var val = state[n]; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2287 if (val instanceof Array) val = val.concat([]); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2288 nstate[n] = val; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2289 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2290 return nstate; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2291 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2292 CodeMirror.copyState = copyState; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2293 function startState(mode, a1, a2) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2294 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
|
2295 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2296 CodeMirror.startState = startState; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2297 CodeMirror.innerMode = function(mode, state) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2298 while (mode.innerMode) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2299 var info = mode.innerMode(state); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2300 state = info.state; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2301 mode = info.mode; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2302 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2303 return info || {mode: mode, state: state}; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2304 }; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2305 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2306 // The character stream used by a mode's parser. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2307 function StringStream(string, tabSize) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2308 this.pos = this.start = 0; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2309 this.string = string; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2310 this.tabSize = tabSize || 8; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2311 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2312 StringStream.prototype = { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2313 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
|
2314 sol: function() {return this.pos == 0;}, |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2315 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
|
2316 next: function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2317 if (this.pos < this.string.length) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2318 return this.string.charAt(this.pos++); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2319 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2320 eat: function(match) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2321 var ch = this.string.charAt(this.pos); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2322 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
|
2323 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
|
2324 if (ok) {++this.pos; return ch;} |
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 eatWhile: function(match) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2327 var start = this.pos; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2328 while (this.eat(match)){} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2329 return this.pos > start; |
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 eatSpace: function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2332 var start = this.pos; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2333 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
|
2334 return this.pos > start; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2335 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2336 skipToEnd: function() {this.pos = this.string.length;}, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2337 skipTo: function(ch) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2338 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
|
2339 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
|
2340 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2341 backUp: function(n) {this.pos -= n;}, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2342 column: function() {return countColumn(this.string, this.start, this.tabSize);}, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2343 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
|
2344 match: function(pattern, consume, caseInsensitive) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2345 if (typeof pattern == "string") { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2346 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
|
2347 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
|
2348 if (consume !== false) this.pos += pattern.length; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2349 return true; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2350 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2351 } else { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2352 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
|
2353 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
|
2354 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
|
2355 return match; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2356 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2357 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2358 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
|
2359 }; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2360 CodeMirror.StringStream = StringStream; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2361 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2362 function MarkedSpan(from, to, marker) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2363 this.from = from; this.to = to; this.marker = marker; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2364 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2365 |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2366 function getMarkedSpanFor(spans, marker) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2367 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
|
2368 var span = spans[i]; |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2369 if (span.marker == marker) return span; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2370 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2371 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2372 |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2373 function removeMarkedSpan(spans, span) { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2374 var r; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2375 for (var i = 0; i < spans.length; ++i) |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2376 if (spans[i] != span) (r || (r = [])).push(spans[i]); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2377 return r; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2378 } |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2379 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2380 function markedSpansBefore(old, startCh, 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 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
|
2384 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
|
2385 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
|
2386 (nw || (nw = [])).push({from: span.from, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2387 to: endsAfter ? null : span.to, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2388 marker: marker}); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2389 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2390 } |
2861
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 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2393 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2394 function markedSpansAfter(old, endCh) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2395 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
|
2396 var span = old[i], marker = span.marker; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2397 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
|
2398 if (endsAfter || marker.type == "bookmark" && span.from == endCh) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2399 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
|
2400 (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
|
2401 to: span.to == null ? null : span.to - endCh, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2402 marker: marker}); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2403 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2404 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2405 return nw; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2406 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2407 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2408 function updateMarkedSpans(oldFirst, oldLast, startCh, endCh, newText) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2409 if (!oldFirst && !oldLast) return newText; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2410 // 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
|
2411 var first = markedSpansBefore(oldFirst, startCh); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2412 var last = markedSpansAfter(oldLast, endCh); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2413 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2414 // Next, merge those two ends |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2415 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
|
2416 if (first) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2417 // Fix up .to properties of first |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2418 for (var i = 0; i < first.length; ++i) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2419 var span = first[i]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2420 if (span.to == null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2421 var found = getMarkedSpanFor(last, span.marker); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2422 if (!found) span.to = startCh; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2423 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
|
2424 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2425 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2426 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2427 if (last) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2428 // 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
|
2429 for (var i = 0; i < last.length; ++i) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2430 var span = last[i]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2431 if (span.to != null) span.to += offset; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2432 if (span.from == null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2433 var found = getMarkedSpanFor(first, span.marker); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2434 if (!found) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2435 span.from = offset; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2436 if (sameLine) (first || (first = [])).push(span); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2437 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2438 } else { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2439 span.from += offset; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2440 if (sameLine) (first || (first = [])).push(span); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2441 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2442 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2443 } |
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 var newMarkers = [newHL(newText[0], first)]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2446 if (!sameLine) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2447 // Fill gap with whole-line-spans |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2448 var gap = newText.length - 2, gapMarkers; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2449 if (gap > 0 && first) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2450 for (var i = 0; i < first.length; ++i) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2451 if (first[i].to == null) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2452 (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
|
2453 for (var i = 0; i < gap; ++i) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2454 newMarkers.push(newHL(newText[i+1], gapMarkers)); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2455 newMarkers.push(newHL(lst(newText), last)); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2456 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2457 return newMarkers; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2458 } |
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 // 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
|
2461 // 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
|
2462 function hlText(val) { return typeof val == "string" ? val : val.text; } |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2463 function hlSpans(val) { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2464 if (typeof val == "string") return null; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2465 var spans = val.markedSpans, out = null; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2466 for (var i = 0; i < spans.length; ++i) { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2467 if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); } |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2468 else if (out) out.push(spans[i]); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2469 } |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2470 return !out ? spans : out.length ? out : null; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2471 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2472 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
|
2473 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2474 function detachMarkedSpans(line) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2475 var spans = line.markedSpans; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2476 if (!spans) return; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2477 for (var i = 0; i < spans.length; ++i) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2478 var lines = spans[i].marker.lines; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2479 var ix = indexOf(lines, line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2480 lines.splice(ix, 1); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2481 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2482 line.markedSpans = null; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2483 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2484 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2485 function attachMarkedSpans(line, spans) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2486 if (!spans) return; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2487 for (var i = 0; i < spans.length; ++i) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2488 var marker = spans[i].marker.lines.push(line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2489 line.markedSpans = spans; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2490 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2491 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2492 // 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
|
2493 // 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
|
2494 // 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
|
2495 // 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
|
2496 // 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
|
2497 // space. |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2498 var eolSpanContent = " "; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2499 if (gecko || (ie && !ie_lt8)) eolSpanContent = "\u200b"; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2500 else if (opera) eolSpanContent = ""; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2501 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2502 // 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
|
2503 // highlighting info (the styles array). |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2504 function Line(text, markedSpans) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2505 this.text = text; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2506 this.height = 1; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2507 attachMarkedSpans(this, markedSpans); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2508 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2509 Line.prototype = { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2510 update: function(text, markedSpans) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2511 this.text = text; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2512 this.stateAfter = this.styles = null; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2513 detachMarkedSpans(this); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2514 attachMarkedSpans(this, markedSpans); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2515 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2516 // 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
|
2517 // 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
|
2518 // classes. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2519 highlight: function(mode, state, tabSize) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2520 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
|
2521 var pos = st.length = 0; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2522 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
|
2523 while (!stream.eol()) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2524 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
|
2525 stream.start = stream.pos; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2526 if (pos && st[pos-1] == style) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2527 st[pos-2] += substr; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2528 } else if (substr) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2529 st[pos++] = substr; st[pos++] = style; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2530 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2531 // Give up when line is ridiculously long |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2532 if (stream.pos > 5000) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2533 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
|
2534 break; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2535 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2536 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2537 }, |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2538 process: function(mode, state, tabSize) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2539 var stream = new StringStream(this.text, tabSize); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2540 if (this.text == "" && mode.blankLine) mode.blankLine(state); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2541 while (!stream.eol() && stream.pos <= 5000) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2542 mode.token(stream, state); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2543 stream.start = stream.pos; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2544 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2545 }, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2546 // 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
|
2547 // 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
|
2548 getTokenAt: function(mode, state, tabSize, ch) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2549 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
|
2550 while (stream.pos < ch && !stream.eol()) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2551 stream.start = stream.pos; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2552 var style = mode.token(stream, state); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2553 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2554 return {start: stream.start, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2555 end: stream.pos, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2556 string: stream.current(), |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2557 className: style || null, |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2558 state: state}; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2559 }, |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2560 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
|
2561 // 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
|
2562 // marking, and highlighting into account. |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2563 getContent: function(tabSize, wrapAt, compensateForWrapping) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2564 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
|
2565 var pre = elt("pre"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2566 function span_(html, text, style) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2567 if (!text) return; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2568 // 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
|
2569 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
|
2570 first = false; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2571 if (!specials.test(text)) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2572 col += text.length; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2573 var content = document.createTextNode(text); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2574 } else { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2575 var content = document.createDocumentFragment(), pos = 0; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2576 while (true) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2577 specials.lastIndex = pos; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2578 var m = specials.exec(text); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2579 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
|
2580 if (skipped) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2581 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
|
2582 col += skipped; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2583 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2584 if (!m) break; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2585 pos += skipped + 1; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2586 if (m[0] == "\t") { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2587 var tabWidth = tabSize - col % tabSize; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2588 content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2589 col += tabWidth; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2590 } else { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2591 var token = elt("span", "\u2022", "cm-invalidchar"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2592 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
|
2593 content.appendChild(token); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2594 col += 1; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2595 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2596 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2597 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2598 if (style) html.appendChild(elt("span", [content], style)); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2599 else html.appendChild(content); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2600 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2601 var span = span_; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2602 if (wrapAt != null) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2603 var outPos = 0, anchor = pre.anchor = elt("span"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2604 span = function(html, text, style) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2605 var l = text.length; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2606 if (wrapAt >= outPos && wrapAt < outPos + l) { |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2607 var cut = wrapAt - outPos; |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2608 if (cut) { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2609 span_(html, text.slice(0, cut), style); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2610 // See comment at the definition of spanAffectsWrapping |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2611 if (compensateForWrapping) { |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2612 var view = text.slice(cut - 1, cut + 1); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2613 if (spanAffectsWrapping.test(view)) html.appendChild(elt("wbr")); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2614 else if (!ie_lt8 && /\w\w/.test(view)) html.appendChild(document.createTextNode("\u200d")); |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2615 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2616 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2617 html.appendChild(anchor); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2618 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
|
2619 if (opera) span_(html, text.slice(cut + 1), style); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2620 wrapAt--; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2621 outPos += l; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2622 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2623 outPos += l; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2624 span_(html, text, style); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2625 if (outPos == wrapAt && outPos == len) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2626 setTextContent(anchor, eolSpanContent); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2627 html.appendChild(anchor); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2628 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2629 // Stop outputting HTML when gone sufficiently far beyond measure |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2630 else if (outPos > wrapAt + 10 && /\s/.test(text)) span = function(){}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2631 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2632 }; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2633 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2634 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2635 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
|
2636 var len = allText.length; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2637 function styleToClass(style) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2638 if (!style) return null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2639 return "cm-" + style.replace(/ +/g, " cm-"); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2640 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2641 if (!allText && wrapAt == null) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2642 span(pre, " "); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2643 } else if (!marked || !marked.length) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2644 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
|
2645 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
|
2646 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
|
2647 ch += l; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2648 span(pre, str, styleToClass(style)); |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2649 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2650 } else { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2651 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
|
2652 var pos = 0, i = 0, text = "", style, sg = 0; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2653 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
|
2654 var advanceMarks = function() { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2655 var m; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2656 while (markpos < marked.length && |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2657 ((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
|
2658 if (m.marker.type == "range") marks.push(m); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2659 ++markpos; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2660 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2661 nextChange = markpos < marked.length ? marked[markpos].from : Infinity; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2662 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
|
2663 var to = marks[i].to; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2664 if (to == null) to = Infinity; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2665 if (to == pos) marks.splice(i--, 1); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2666 else nextChange = Math.min(to, nextChange); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2667 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2668 }; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2669 var m = 0; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2670 while (pos < len) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2671 if (nextChange == pos) advanceMarks(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2672 var upto = Math.min(len, nextChange); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2673 while (true) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2674 if (text) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2675 var end = pos + text.length; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2676 var appliedStyle = style; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2677 for (var j = 0; j < marks.length; ++j) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2678 var mark = marks[j]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2679 appliedStyle = (appliedStyle ? appliedStyle + " " : "") + mark.marker.style; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2680 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
|
2681 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
|
2682 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2683 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
|
2684 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
|
2685 pos = end; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2686 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2687 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
|
2688 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2689 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2690 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2691 return pre; |
2547
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 cleanUp: function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2694 this.parent = null; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2695 detachMarkedSpans(this); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2696 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2697 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2698 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2699 // Data structure that holds the sequence of lines. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2700 function LeafChunk(lines) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2701 this.lines = lines; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2702 this.parent = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2703 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
|
2704 lines[i].parent = this; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2705 height += lines[i].height; |
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 this.height = height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2708 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2709 LeafChunk.prototype = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2710 chunkSize: function() { return this.lines.length; }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2711 remove: function(at, n, callbacks) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2712 for (var i = at, e = at + n; i < e; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2713 var line = this.lines[i]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2714 this.height -= line.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2715 line.cleanUp(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2716 if (line.handlers) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2717 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
|
2718 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2719 this.lines.splice(at, n); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2720 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2721 collapse: function(lines) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2722 lines.splice.apply(lines, [lines.length, 0].concat(this.lines)); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2723 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2724 insertHeight: function(at, lines, height) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2725 this.height += height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2726 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
|
2727 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
|
2728 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2729 iterN: function(at, n, op) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2730 for (var e = at + n; at < e; ++at) |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2731 if (op(this.lines[at])) return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2732 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2733 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2734 function BranchChunk(children) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2735 this.children = children; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2736 var size = 0, height = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2737 for (var i = 0, e = children.length; i < e; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2738 var ch = children[i]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2739 size += ch.chunkSize(); height += ch.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2740 ch.parent = this; |
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 this.size = size; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2743 this.height = height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2744 this.parent = null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2745 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2746 BranchChunk.prototype = { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2747 chunkSize: function() { return this.size; }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2748 remove: function(at, n, callbacks) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2749 this.size -= n; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2750 for (var i = 0; i < this.children.length; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2751 var child = this.children[i], sz = child.chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2752 if (at < sz) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2753 var rm = Math.min(n, sz - at), oldHeight = child.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2754 child.remove(at, rm, callbacks); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2755 this.height -= oldHeight - child.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2756 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
|
2757 if ((n -= rm) == 0) break; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2758 at = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2759 } else at -= sz; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2760 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2761 if (this.size - n < 25) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2762 var lines = []; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2763 this.collapse(lines); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2764 this.children = [new LeafChunk(lines)]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2765 this.children[0].parent = this; |
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 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2768 collapse: function(lines) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2769 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
|
2770 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2771 insert: function(at, lines) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2772 var height = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2773 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
|
2774 this.insertHeight(at, lines, height); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2775 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2776 insertHeight: function(at, lines, height) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2777 this.size += lines.length; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2778 this.height += height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2779 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
|
2780 var child = this.children[i], sz = child.chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2781 if (at <= sz) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2782 child.insertHeight(at, lines, height); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2783 if (child.lines && child.lines.length > 50) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2784 while (child.lines.length > 50) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2785 var spilled = child.lines.splice(child.lines.length - 25, 25); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2786 var newleaf = new LeafChunk(spilled); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2787 child.height -= newleaf.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2788 this.children.splice(i + 1, 0, newleaf); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2789 newleaf.parent = this; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2790 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2791 this.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 break; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2794 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2795 at -= sz; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2796 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2797 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2798 maybeSpill: function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2799 if (this.children.length <= 10) return; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2800 var me = this; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2801 do { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2802 var spilled = me.children.splice(me.children.length - 5, 5); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2803 var sibling = new BranchChunk(spilled); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2804 if (!me.parent) { // Become the parent node |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2805 var copy = new BranchChunk(me.children); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2806 copy.parent = me; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2807 me.children = [copy, sibling]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2808 me = copy; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2809 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2810 me.size -= sibling.size; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2811 me.height -= sibling.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2812 var myIndex = indexOf(me.parent.children, me); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2813 me.parent.children.splice(myIndex + 1, 0, sibling); |
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 sibling.parent = me.parent; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2816 } while (me.children.length > 10); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2817 me.parent.maybeSpill(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2818 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2819 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
|
2820 iterN: function(at, n, op) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2821 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
|
2822 var child = this.children[i], sz = child.chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2823 if (at < sz) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2824 var used = Math.min(n, sz - at); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2825 if (child.iterN(at, used, op)) return true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2826 if ((n -= used) == 0) break; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2827 at = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2828 } else at -= sz; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2829 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2830 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2831 }; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2832 |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2833 function getLineAt(chunk, n) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2834 while (!chunk.lines) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2835 for (var i = 0;; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2836 var child = chunk.children[i], sz = child.chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2837 if (n < sz) { chunk = child; break; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2838 n -= sz; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2839 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2840 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2841 return chunk.lines[n]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2842 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2843 function lineNo(line) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2844 if (line.parent == null) return null; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2845 var cur = line.parent, no = indexOf(cur.lines, line); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2846 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
|
2847 for (var i = 0, e = chunk.children.length; ; ++i) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2848 if (chunk.children[i] == cur) break; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2849 no += chunk.children[i].chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2850 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2851 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2852 return no; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2853 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2854 function lineAtHeight(chunk, h) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2855 var n = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2856 outer: do { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2857 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
|
2858 var child = chunk.children[i], ch = child.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2859 if (h < ch) { chunk = child; continue outer; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2860 h -= ch; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2861 n += child.chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2862 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2863 return n; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2864 } while (!chunk.lines); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2865 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
|
2866 var line = chunk.lines[i], lh = line.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2867 if (h < lh) break; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2868 h -= lh; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2869 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2870 return n + i; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2871 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2872 function heightAtLine(chunk, n) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2873 var h = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2874 outer: do { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2875 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
|
2876 var child = chunk.children[i], sz = child.chunkSize(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2877 if (n < sz) { chunk = child; continue outer; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2878 n -= sz; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2879 h += child.height; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2880 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2881 return h; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2882 } while (!chunk.lines); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2883 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
|
2884 return h; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2885 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2886 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2887 // 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
|
2888 // 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
|
2889 function History() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2890 this.time = 0; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2891 this.done = []; this.undone = []; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2892 this.compound = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2893 this.closed = false; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2894 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2895 History.prototype = { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2896 addChange: function(start, added, old) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2897 this.undone.length = 0; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2898 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
|
2899 var dtime = time - this.time; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2900 |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
2901 if (cur && !this.closed && this.compound) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2902 cur.push({start: start, added: added, old: old}); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2903 } else if (dtime > 400 || !last || this.closed || |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2904 last.start > start + old.length || last.start + last.added < start) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2905 this.done.push([{start: start, added: added, old: old}]); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2906 this.closed = false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2907 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2908 var startBefore = Math.max(0, last.start - start), |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2909 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
|
2910 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
|
2911 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
|
2912 if (startBefore) last.start = start; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2913 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
|
2914 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2915 this.time = time; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2916 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2917 startCompound: function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2918 if (!this.compound++) this.closed = true; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2919 }, |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2920 endCompound: function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2921 if (!--this.compound) this.closed = true; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2922 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2923 }; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2924 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2925 function stopMethod() {e_stop(this);} |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2926 // Ensure an event has a stop method. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2927 function addStop(event) { |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2928 if (!event.stop) event.stop = stopMethod; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2929 return event; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2930 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2931 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2932 function e_preventDefault(e) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2933 if (e.preventDefault) e.preventDefault(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2934 else e.returnValue = false; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2935 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2936 function e_stopPropagation(e) { |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2937 if (e.stopPropagation) e.stopPropagation(); |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2938 else e.cancelBubble = true; |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2939 } |
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2940 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
|
2941 CodeMirror.e_stop = e_stop; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2942 CodeMirror.e_preventDefault = e_preventDefault; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2943 CodeMirror.e_stopPropagation = e_stopPropagation; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2944 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2945 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
|
2946 function e_button(e) { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2947 var b = e.which; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2948 if (b == null) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2949 if (e.button & 1) b = 1; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2950 else if (e.button & 2) b = 3; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2951 else if (e.button & 4) b = 2; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2952 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2953 if (mac && e.ctrlKey && b == 1) b = 3; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2954 return b; |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
2955 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2956 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2957 // 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
|
2958 // object to an event object. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2959 function e_prop(e, prop) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2960 var overridden = e.override && e.override.hasOwnProperty(prop); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2961 return overridden ? e.override[prop] : e[prop]; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2962 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2963 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2964 // 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
|
2965 // function that unregisters the handler. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2966 function connect(node, type, handler, disconnect) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2967 if (typeof node.addEventListener == "function") { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2968 node.addEventListener(type, handler, false); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2969 if (disconnect) return function() {node.removeEventListener(type, handler, false);}; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2970 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2971 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
|
2972 node.attachEvent("on" + type, wrapHandler); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2973 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
|
2974 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2975 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2976 CodeMirror.connect = connect; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2977 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2978 function Delayed() {this.id = null;} |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2979 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
|
2980 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2981 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
|
2982 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2983 // Detect drag-and-drop |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2984 var dragAndDrop = function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2985 // 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
|
2986 // couldn't get it to work yet. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2987 if (ie_lt9) return false; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2988 var div = elt('div'); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2989 return "draggable" in div || "dragDrop" in div; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2990 }(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2991 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2992 // 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
|
2993 var lineSep = function () { |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
2994 var te = elt("textarea"); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2995 te.value = "foo\nbar"; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2996 if (te.value.indexOf("\r") > -1) return "\r\n"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2997 return "\n"; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
2998 }(); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2999 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3000 // 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
|
3001 // word wrapping between certain characters *only* if a new inline |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3002 // 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
|
3003 // measure the position of things, since that requires inserting an |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3004 // extra span. This terribly fragile set of regexps matches the |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3005 // character combinations that suffer from this phenomenon on the |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3006 // various browsers. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3007 var spanAffectsWrapping = /^$/; // Won't match any two-character string |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3008 if (gecko) spanAffectsWrapping = /$'/; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3009 else if (safari) spanAffectsWrapping = /\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3010 else if (chrome) spanAffectsWrapping = /\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3011 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3012 // 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
|
3013 // Used mostly to find indentation. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3014 function countColumn(string, end, tabSize) { |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3015 if (end == null) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3016 end = string.search(/[^\s\u00a0]/); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3017 if (end == -1) end = string.length; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3018 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3019 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
|
3020 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
|
3021 else ++n; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3022 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3023 return n; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3024 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3025 |
1606
a30689fc4f61
bumped codemirror to latest version
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
3026 function eltOffset(node, screen) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3027 // 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
|
3028 // 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
|
3029 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
|
3030 catch(e) { box = {top: 0, left: 0}; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3031 if (!screen) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3032 // Get the toplevel scroll, working around browser differences. |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3033 if (window.pageYOffset == null) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3034 var t = document.documentElement || document.body.parentNode; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3035 if (t.scrollTop == null) t = document.body; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3036 box.top += t.scrollTop; box.left += t.scrollLeft; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3037 } else { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3038 box.top += window.pageYOffset; box.left += window.pageXOffset; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3039 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3040 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3041 return box; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3042 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3043 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3044 function eltText(node) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3045 return node.textContent || node.innerText || node.nodeValue || ""; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3046 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3047 |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3048 var spaceStrs = [""]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3049 function spaceStr(n) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3050 while (spaceStrs.length <= n) |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3051 spaceStrs.push(lst(spaceStrs) + " "); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3052 return spaceStrs[n]; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3053 } |
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 lst(arr) { return arr[arr.length-1]; } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3056 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3057 function selectInput(node) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3058 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
|
3059 node.selectionStart = 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3060 node.selectionEnd = node.value.length; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3061 } else node.select(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3062 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3063 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3064 // Operations on {line, ch} objects. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3065 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
|
3066 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
|
3067 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
|
3068 |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3069 function elt(tag, content, className, style) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3070 var e = document.createElement(tag); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3071 if (className) e.className = className; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3072 if (style) e.style.cssText = style; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3073 if (typeof content == "string") setTextContent(e, content); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3074 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
|
3075 return e; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3076 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3077 function removeChildren(e) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3078 e.innerHTML = ""; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3079 return e; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3080 } |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3081 function removeChildrenAndAdd(parent, e) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3082 removeChildren(parent).appendChild(e); |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3083 } |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3084 function setTextContent(e, str) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3085 if (ie_lt9) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3086 e.innerHTML = ""; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3087 e.appendChild(document.createTextNode(str)); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3088 } else e.textContent = str; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3089 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3090 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3091 // 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
|
3092 // last edited character. |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3093 function editEnd(from, to) { |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3094 if (!to) return 0; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3095 if (!from) return to.length; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3096 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
|
3097 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
|
3098 return j + 1; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3099 } |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3100 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3101 function indexOf(collection, elt) { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3102 if (collection.indexOf) return collection.indexOf(elt); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3103 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
|
3104 if (collection[i] == elt) return i; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3105 return -1; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3106 } |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
3107 var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc]/; |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3108 function isWordChar(ch) { |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
3109 return /\w/.test(ch) || ch > "\x80" && |
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
3110 (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)); |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3111 } |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3112 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3113 // 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
|
3114 // alternative way to split lines. |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3115 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
|
3116 var pos = 0, result = [], l = string.length; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3117 while (pos <= l) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3118 var nl = string.indexOf("\n", pos); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3119 if (nl == -1) nl = string.length; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3120 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
|
3121 var rt = line.indexOf("\r"); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3122 if (rt != -1) { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3123 result.push(line.slice(0, rt)); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3124 pos += rt + 1; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3125 } else { |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3126 result.push(line); |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3127 pos = nl + 1; |
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3128 } |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3129 } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3130 return result; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3131 } : 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
|
3132 CodeMirror.splitLines = splitLines; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3133 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3134 var hasSelection = window.getSelection ? function(te) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3135 try { return te.selectionStart != te.selectionEnd; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3136 catch(e) { return false; } |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3137 } : function(te) { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3138 try {var range = te.ownerDocument.selection.createRange();} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3139 catch(e) {} |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3140 if (!range || range.parentElement() != te) return false; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3141 return range.compareEndPoints("StartToEnd", range) != 0; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3142 }; |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3143 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3144 CodeMirror.defineMode("null", function() { |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3145 return {token: function(stream) {stream.skipToEnd();}}; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3146 }); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3147 CodeMirror.defineMIME("text/plain", "null"); |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3148 |
2547
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3149 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
|
3150 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
|
3151 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
|
3152 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
|
3153 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3154 221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home", |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3155 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
|
3156 CodeMirror.keyNames = keyNames; |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3157 (function() { |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3158 // Number keys |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3159 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
|
3160 // Alphabetic keys |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3161 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
|
3162 // Function keys |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3163 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
|
3164 })(); |
01273e4f8d63
Updated codemirror script
Marcin Kuzminski <marcin@python-works.com>
parents:
1606
diff
changeset
|
3165 |
3036
31f98c850623
updated codemirror version
Marcin Kuzminski <marcin@python-works.com>
parents:
2861
diff
changeset
|
3166 CodeMirror.version = "2.36"; |
2861
f034e6a13a5e
updated codemirror to 2.34
Marcin Kuzminski <marcin@python-works.com>
parents:
2547
diff
changeset
|
3167 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3168 return CodeMirror; |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3169 })(); |