Skip to content

Commit eaa3e2d

Browse files
author
Roman Sutormin
committed
Merge pull request #15 from hoffman373/master
Added focus and getLineCount methods.
2 parents d052711 + a9d5b0d commit eaa3e2d

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

AceGWT/src/edu/ycp/cs/dh/acegwt/client/ace/AceEditor.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,24 @@ public native String getText() /*-{
226226
return editor.getSession().getValue();
227227
}-*/;
228228

229-
229+
/**
230+
* Causes the editor to gain input focus.
231+
*/
232+
public native void focus() /*-{
233+
var editor = [email protected]::editor;
234+
editor.focus();
235+
}-*/;
236+
237+
/**
238+
* Retrieves the number of lines in the editor.
239+
*
240+
* @return The number of lines in the editor.
241+
*/
242+
public native int getLineCount() /*-{
243+
var editor = [email protected]::editor;
244+
return editor.session.getLength();
245+
}-*/;
246+
230247
/**
231248
* Set the complete text in the editor from a String.
232249
*

AceGWTDemo/src/edu/ycp/cs/dh/acegwt/client/demo/client/AceGWTDemo.java

+33
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,39 @@ public void onClick(ClickEvent event) {
336336

337337
mainPanel.add(editor2);
338338
mainPanel.add(new Label("Label below!"));
339+
340+
// Demo button for get number of lines
341+
final Button appendLineCount = new Button("Append Line Count");
342+
appendLineCount.addClickHandler(new ClickHandler() {
343+
@Override
344+
public void onClick(ClickEvent event) {
345+
final String message = editor2.getText() + "There are "
346+
+ editor1.getLineCount() + " lines in the main editor.";
347+
editor2.setText(message);
348+
}
349+
350+
});
351+
buttonPanel2.add(appendLineCount);
352+
353+
final Button flipFocus = new Button("Focus 1st Editor");
354+
flipFocus.addClickHandler(new ClickHandler() {
355+
@Override
356+
public void onClick(ClickEvent event) {
357+
editor1.focus();
358+
}
359+
360+
});
361+
buttonPanel2.add(flipFocus);
362+
363+
final Button flipFocus2 = new Button("Focus 2nd Editor");
364+
flipFocus2.addClickHandler(new ClickHandler() {
365+
@Override
366+
public void onClick(ClickEvent event) {
367+
editor2.focus();
368+
}
369+
370+
});
371+
buttonPanel2.add(flipFocus2);
339372

340373
RootPanel.get().add(mainPanel);
341374
}

0 commit comments

Comments
 (0)