Skip to content

Commit

Permalink
Merge pull request #15 from hoffman373/master
Browse files Browse the repository at this point in the history
Added focus and getLineCount methods.
  • Loading branch information
Roman Sutormin committed Feb 13, 2015
2 parents d052711 + a9d5b0d commit eaa3e2d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
19 changes: 18 additions & 1 deletion AceGWT/src/edu/ycp/cs/dh/acegwt/client/ace/AceEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,24 @@ public native String getText() /*-{
return editor.getSession().getValue();
}-*/;


/**
* Causes the editor to gain input focus.
*/
public native void focus() /*-{
var editor = [email protected]::editor;
editor.focus();
}-*/;

/**
* Retrieves the number of lines in the editor.
*
* @return The number of lines in the editor.
*/
public native int getLineCount() /*-{
var editor = [email protected]::editor;
return editor.session.getLength();
}-*/;

/**
* Set the complete text in the editor from a String.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,39 @@ public void onClick(ClickEvent event) {

mainPanel.add(editor2);
mainPanel.add(new Label("Label below!"));

// Demo button for get number of lines
final Button appendLineCount = new Button("Append Line Count");
appendLineCount.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final String message = editor2.getText() + "There are "
+ editor1.getLineCount() + " lines in the main editor.";
editor2.setText(message);
}

});
buttonPanel2.add(appendLineCount);

final Button flipFocus = new Button("Focus 1st Editor");
flipFocus.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
editor1.focus();
}

});
buttonPanel2.add(flipFocus);

final Button flipFocus2 = new Button("Focus 2nd Editor");
flipFocus2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
editor2.focus();
}

});
buttonPanel2.add(flipFocus2);

RootPanel.get().add(mainPanel);
}
Expand Down

0 comments on commit eaa3e2d

Please sign in to comment.