aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/LocalFilesEditor/codemirror/lib/overlay.js
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2011-04-12 11:12:51 +0000
committerpatdenice <patdenice@piwigo.org>2011-04-12 11:12:51 +0000
commita740ef91e6689f86011b70c7bbe2589abf78ae6b (patch)
treebb4a6deb7395b0f545bb760cf34f093e910f1cff /plugins/LocalFilesEditor/codemirror/lib/overlay.js
parentbb7c28f86febddd376ee0400807507991a2d7b48 (diff)
feature:2262
Replace editarea by Codemirror: http://codemirror.net git-svn-id: http://piwigo.org/svn/trunk@10307 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--plugins/LocalFilesEditor/codemirror/lib/overlay.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/LocalFilesEditor/codemirror/lib/overlay.js b/plugins/LocalFilesEditor/codemirror/lib/overlay.js
new file mode 100644
index 000000000..c4cdf9fc8
--- /dev/null
+++ b/plugins/LocalFilesEditor/codemirror/lib/overlay.js
@@ -0,0 +1,51 @@
+// Utility function that allows modes to be combined. The mode given
+// as the base argument takes care of most of the normal mode
+// functionality, but a second (typically simple) mode is used, which
+// can override the style of text. Both modes get to parse all of the
+// text, but when both assign a non-null style to a piece of code, the
+// overlay wins, unless the combine argument was true, in which case
+// the styles are combined.
+
+CodeMirror.overlayParser = function(base, overlay, combine) {
+ return {
+ startState: function() {
+ return {
+ base: CodeMirror.startState(base),
+ overlay: CodeMirror.startState(overlay),
+ basePos: 0, baseCur: null,
+ overlayPos: 0, overlayCur: null
+ };
+ },
+ copyState: function(state) {
+ return {
+ base: CodeMirror.copyState(base, state.base),
+ overlay: CodeMirror.copyState(overlay, state.overlay),
+ basePos: state.basePos, baseCur: null,
+ overlayPos: state.overlayPos, overlayCur: null
+ };
+ },
+
+ token: function(stream, state) {
+ if (stream.start == state.basePos) {
+ state.baseCur = base.token(stream, state.base);
+ state.basePos = stream.pos;
+ }
+ if (stream.start == state.overlayPos) {
+ stream.pos = stream.start;
+ state.overlayCur = overlay.token(stream, state.overlay);
+ state.overlayPos = stream.pos;
+ }
+ stream.pos = Math.min(state.basePos, state.overlayPos);
+ if (stream.eol()) state.basePos = state.overlayPos = 0;
+
+ if (state.overlayCur == null) return state.baseCur;
+ if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
+ else return state.overlayCur;
+ },
+
+ indent: function(state, textAfter) {
+ return base.indent(state.base, textAfter);
+ },
+ electricChars: base.electricChars
+ };
+};