Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 45 lines (40 sloc) 1.438 kb
4638573b »
2011-12-11 Revamped auto-matching macros to deal more gracefully with things lik…
1 insert(textArea, sc, ec, init) {
2 if (textArea.getSelectionCount() == 0) {
3 sel = new Selection.Range(textArea.getCaretPosition(), textArea.getCaretPosition());
4 } else if (init && textArea.getSelectionCount() == 1 && textArea.getSelection()[0] instanceof Selection.Range) {
5 sel = textArea.getSelection()[0];
6 } else {
7 // TODO?
8 selections = textArea.getSelection();
9 for (int i = 0; i < selections.length; i++) {
10 textArea.setSelectedText(selections[i], init ? sc : ec);
11 }
12 return;
13 }
14
15 if (init) {
16 position = textArea.getCaretPosition();
17 prior = new Selection.Range(sel.getStart(), sel.getStart());
18 post = new Selection.Range(sel.getEnd() + 1, sel.getEnd() + 1);
19 textArea.setSelectedText(prior, sc);
20 textArea.setSelectedText(post, ec);
21
22 if (position >= prior.getStart()) {
23 position++;
24 }
25 if (position > post.getEnd()) {
26 position++;
27 }
28
29 textArea.moveCaretPosition(position);
30 textArea.setSelection(new Selection.Range(sel.getStart(), Math.max(sel.getStart(), sel.getEnd() - 1)));
31 } else {
32 target = new Selection.Range(sel.getEnd(), sel.getEnd() + 1);
33 if (target.getEnd() <= textArea.getBufferLength()) {
34 if (!textArea.getSelectedText(target).equals(ec)) {
35 textArea.setSelectedText(new Selection.Range(sel.getEnd(), sel.getEnd()), ec);
36 }
37 textArea.setCaretPosition(sel.getEnd() + 1);
38 } else {
39 textArea.setSelectedText(ec, true);
40 }
41 }
42815cba »
2011-09-22 Initial setup
42 }
4638573b »
2011-12-11 Revamped auto-matching macros to deal more gracefully with things lik…
43
44 insert(textArea, "(", ")", false);
Something went wrong with that request. Please try again.