Add CodeMirrorDoc and the code folding addon.

Add wrappers around CodeMirrorDoc, which supports manipulating the
contents in CMs.

Add foldcode.js addon. This lays the foundation for handling skips.

Change-Id: Ib5df6487b0fcde9bb3395ec64cf84fcf7ff125c1
This commit is contained in:
Michael Zhou 2013-06-20 16:17:10 -07:00
parent abf646c761
commit b206a4062e
4 changed files with 42 additions and 0 deletions

View File

@ -25,4 +25,8 @@ public interface Addons extends ClientBundle {
@Source("selection/mark-selection.js")
@DoNotEmbed
DataResource mark_selection();
@Source("fold/foldcode.js")
@DoNotEmbed
DataResource foldcode();
}

View File

@ -71,6 +71,10 @@ public class CodeMirror extends JavaScriptObject {
this.addLineWidget(line, node, options);
}-*/;
public final native CodeMirrorDoc getDoc() /*-{
return this.getDoc();
}-*/;
public final native void scrollTo(int x, int y) /*-{
this.scrollTo(x, y);
}-*/;

View File

@ -0,0 +1,33 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package net.codemirror.lib;
import com.google.gwt.core.client.JavaScriptObject;
/** The Doc object representing the content in a CodeMirror */
public class CodeMirrorDoc extends JavaScriptObject {
public final native void replaceRange(String replacement,
LineCharacter from, LineCharacter to) /*-{
this.replaceRange(replacement, from, to);
}-*/;
public final native void insertText(String insertion, LineCharacter at) /*-{
this.replaceRange(insertion, at);
}-*/;
protected CodeMirrorDoc() {
}
}

View File

@ -47,6 +47,7 @@ class Loader {
public void onSuccess(Void result) {}
}));
injectScript(Addons.I.mark_selection().getSafeUri(), group.add(cb));
injectScript(Addons.I.foldcode().getSafeUri(), group.add(cb));
}
}