Skip to content

Commit 673fc51

Browse files
committed
Remove partial support for rectangular selections.
1 parent aad493e commit 673fc51

File tree

4 files changed

+10
-163
lines changed

4 files changed

+10
-163
lines changed

app/src/processing/app/syntax/DefaultInputHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void addDefaultKeyBindings()
4646
addKeyBinding("TAB",INSERT_TAB);
4747

4848
addKeyBinding("INSERT",OVERWRITE);
49-
addKeyBinding("C+\\",TOGGLE_RECT);
5049

5150
addKeyBinding("HOME",HOME);
5251
addKeyBinding("END",END);

app/src/processing/app/syntax/InputHandler.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public abstract class InputHandler extends KeyAdapter
8484
public static final ActionListener SELECT_PREV_PAGE = new prev_page(true);
8585
public static final ActionListener SELECT_PREV_WORD = new prev_word(true);
8686
public static final ActionListener REPEAT = new repeat();
87-
public static final ActionListener TOGGLE_RECT = new toggle_rect();
8887
public static final ActionListener CLIPBOARD_CUT = new clipboard_cut(); // [fry]
8988
public static final ActionListener CLIPBOARD_COPY = new clipboard_copy();
9089
public static final ActionListener CLIPBOARD_PASTE = new clipboard_paste();
@@ -133,7 +132,6 @@ public abstract class InputHandler extends KeyAdapter
133132
actions.put("select-prev-page",SELECT_PREV_PAGE);
134133
actions.put("select-prev-word",SELECT_PREV_WORD);
135134
actions.put("repeat",REPEAT);
136-
actions.put("toggle-rect",TOGGLE_RECT);
137135
actions.put("insert-char",INSERT_CHAR);
138136
actions.put("clipboard-cut",CLIPBOARD_CUT);
139137
actions.put("clipboard-copy",CLIPBOARD_COPY);
@@ -1060,14 +1058,6 @@ public void actionPerformed(ActionEvent evt) {
10601058
}
10611059

10621060

1063-
public static class toggle_rect implements ActionListener {
1064-
public void actionPerformed(ActionEvent evt) {
1065-
JEditTextArea textArea = getTextArea(evt);
1066-
textArea.setSelectionRectangular(!textArea.isSelectionRectangular());
1067-
}
1068-
}
1069-
1070-
10711061
public static class clipboard_cut implements ActionListener {
10721062
public void actionPerformed(ActionEvent evt) {
10731063
getTextArea(evt).cut();

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 9 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,19 +1072,8 @@ public final int getSelectionStart() {
10721072
*/
10731073
public int getSelectionStart(int line)
10741074
{
1075-
if(line == selectionStartLine)
1075+
if (line == selectionStartLine)
10761076
return selectionStart;
1077-
else if(rectSelect)
1078-
{
1079-
Element map = document.getDefaultRootElement();
1080-
int start = selectionStart - map.getElement(selectionStartLine)
1081-
.getStartOffset();
1082-
1083-
Element lineElement = map.getElement(line);
1084-
int lineStart = lineElement.getStartOffset();
1085-
int lineEnd = lineElement.getEndOffset() - 1;
1086-
return Math.min(lineEnd,lineStart + start);
1087-
}
10881077
else
10891078
return getLineStartOffset(line);
10901079
}
@@ -1122,19 +1111,8 @@ public final int getSelectionStop()
11221111
*/
11231112
public int getSelectionStop(int line)
11241113
{
1125-
if(line == selectionEndLine)
1114+
if (line == selectionEndLine)
11261115
return selectionEnd;
1127-
else if(rectSelect)
1128-
{
1129-
Element map = document.getDefaultRootElement();
1130-
int end = selectionEnd - map.getElement(selectionEndLine)
1131-
.getStartOffset();
1132-
1133-
Element lineElement = map.getElement(line);
1134-
int lineStart = lineElement.getStartOffset();
1135-
int lineEnd = lineElement.getEndOffset() - 1;
1136-
return Math.min(lineEnd,lineStart + end);
1137-
}
11381116
else
11391117
return getLineStopOffset(line) - 1;
11401118
}
@@ -1297,10 +1275,6 @@ public void select(int start, int end)
12971275
caretTimer.restart();
12981276
}
12991277

1300-
// Disable rectangle select if selection start = selection end
1301-
if(selectionStart == selectionEnd)
1302-
rectSelect = false;
1303-
13041278
// Clear the `magic' caret position used by up/down
13051279
magicCaret = -1;
13061280

@@ -1380,54 +1354,10 @@ protected void setNewSelectionWord( int line, int offset )
13801354
*/
13811355
public final String getSelectedText()
13821356
{
1383-
if(selectionStart == selectionEnd)
1357+
if (selectionStart == selectionEnd) {
13841358
return null;
1385-
1386-
if(rectSelect)
1387-
{
1388-
// Return each row of the selection on a new line
1389-
1390-
Element map = document.getDefaultRootElement();
1391-
1392-
int start = selectionStart - map.getElement(selectionStartLine)
1393-
.getStartOffset();
1394-
int end = selectionEnd - map.getElement(selectionEndLine)
1395-
.getStartOffset();
1396-
1397-
// Certain rectangles satisfy this condition...
1398-
if(end < start)
1399-
{
1400-
int tmp = end;
1401-
end = start;
1402-
start = tmp;
1403-
}
1404-
1405-
StringBuilder sb = new StringBuilder();
1406-
Segment seg = new Segment();
1407-
1408-
for(int i = selectionStartLine; i <= selectionEndLine; i++)
1409-
{
1410-
Element lineElement = map.getElement(i);
1411-
int lineStart = lineElement.getStartOffset();
1412-
int lineEnd = lineElement.getEndOffset() - 1;
1413-
int lineLen = lineEnd - lineStart;
1414-
1415-
lineStart = Math.min(lineStart + start,lineEnd);
1416-
lineLen = Math.min(end - start,lineEnd - lineStart);
1417-
1418-
getText(lineStart,lineLen,seg);
1419-
sb.append(seg.array,seg.offset,seg.count);
1420-
1421-
if(i != selectionEndLine)
1422-
sb.append('\n');
1423-
}
1424-
1425-
return sb.toString();
1426-
}
1427-
else
1428-
{
1429-
return getText(selectionStart,
1430-
selectionEnd - selectionStart);
1359+
} else {
1360+
return getText(selectionStart, selectionEnd - selectionStart);
14311361
}
14321362
}
14331363

@@ -1456,55 +1386,11 @@ public void setSelectedText(String selectedText, boolean recordCompoundEdit) {
14561386
}
14571387

14581388
try {
1459-
if (rectSelect) {
1460-
Element map = document.getDefaultRootElement();
1461-
1462-
int start = selectionStart -
1463-
map.getElement(selectionStartLine).getStartOffset();
1464-
int end = selectionEnd -
1465-
map.getElement(selectionEndLine).getStartOffset();
1466-
1467-
// Certain rectangles satisfy this condition...
1468-
if (end < start) {
1469-
int tmp = end;
1470-
end = start;
1471-
start = tmp;
1472-
}
1473-
1474-
int lastNewline = 0;
1475-
int currNewline = 0;
1476-
1477-
for (int i = selectionStartLine; i <= selectionEndLine; i++) {
1478-
Element lineElement = map.getElement(i);
1479-
int lineStart = lineElement.getStartOffset();
1480-
int lineEnd = lineElement.getEndOffset() - 1;
1481-
int rectStart = Math.min(lineEnd,lineStart + start);
1482-
1483-
document.remove(rectStart,Math.min(lineEnd - rectStart, end - start));
1484-
1485-
if (selectedText != null) {
1486-
currNewline = selectedText.indexOf('\n', lastNewline);
1487-
if (currNewline == -1) {
1488-
currNewline = selectedText.length();
1489-
}
1490-
document.insertString(rectStart, selectedText.substring(lastNewline, currNewline), null);
1491-
lastNewline = Math.min(selectedText.length(), currNewline + 1);
1492-
}
1493-
}
1494-
1495-
if (selectedText != null &&
1496-
currNewline != selectedText.length()) {
1497-
int offset = map.getElement(selectionEndLine).getEndOffset() - 1;
1498-
document.insertString(offset, "\n", null);
1499-
document.insertString(offset + 1,selectedText.substring(currNewline + 1), null);
1500-
}
1501-
} else {
1502-
document.remove(selectionStart, selectionEnd - selectionStart);
1503-
if (selectedText != null) {
1504-
document.insertString(selectionStart, selectedText,null);
1505-
}
1389+
document.remove(selectionStart, selectionEnd - selectionStart);
1390+
if (selectedText != null) {
1391+
document.insertString(selectionStart, selectedText,null);
15061392
}
1507-
} catch(BadLocationException bl) {
1393+
} catch (BadLocationException bl) {
15081394
bl.printStackTrace();
15091395
throw new InternalError("Cannot replace selection");
15101396

@@ -1632,24 +1518,6 @@ public final void setOverwriteEnabled(boolean overwrite)
16321518
painter.invalidateSelectedLines();
16331519
}
16341520

1635-
/**
1636-
* Returns true if the selection is rectangular, false otherwise.
1637-
*/
1638-
public final boolean isSelectionRectangular()
1639-
{
1640-
return rectSelect;
1641-
}
1642-
1643-
/**
1644-
* Sets if the selection should be rectangular.
1645-
* @param rectSelect True if the selection should be rectangular,
1646-
* false otherwise.
1647-
*/
1648-
public final void setSelectionRectangular(boolean rectSelect)
1649-
{
1650-
this.rectSelect = rectSelect;
1651-
painter.invalidateSelectedLines();
1652-
}
16531521

16541522
/**
16551523
* Returns the position of the highlighted bracket (the bracket
@@ -2071,7 +1939,6 @@ public void processKeyEvent(KeyEvent event) {
20711939

20721940
protected int magicCaret;
20731941
protected boolean overwrite;
2074-
protected boolean rectSelect;
20751942

20761943

20771944
protected void fireCaretEvent()
@@ -2391,8 +2258,6 @@ public void mouseDragged(MouseEvent evt) {
23912258
if (popup != null && popup.isVisible()) return;
23922259

23932260
if (!selectWord && !selectLine) {
2394-
//setSelectionRectangular((evt.getModifiers() & InputEvent.CTRL_MASK) != 0);
2395-
setSelectionRectangular(evt.isControlDown());
23962261
try {
23972262
select(getMarkPosition(), xyToOffset(evt.getX(), evt.getY()));
23982263
} catch (ArrayIndexOutOfBoundsException e) {
@@ -2531,7 +2396,6 @@ public void mouseReleased(MouseEvent event) {
25312396

25322397
private void doSingleClick(MouseEvent evt, int line, int offset, int dot) {
25332398
if ((evt.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
2534-
rectSelect = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0;
25352399
select(getMarkPosition(),dot);
25362400
} else {
25372401
setCaretPosition(dot);

app/src/processing/app/syntax/TextAreaPainter.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,13 +833,7 @@ protected void paintLineHighlight(Graphics gfx, int line, int y) {
833833
int lineStart = textArea.getLineStartOffset(line);
834834

835835
int x1, x2;
836-
if (textArea.isSelectionRectangular()) {
837-
int lineLen = textArea.getLineLength(line);
838-
x1 = textArea._offsetToX(line,Math.min(lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine)));
839-
x2 = textArea._offsetToX(line,Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine)));
840-
if (x1 == x2)
841-
x2++;
842-
} else if(selectionStartLine == selectionEndLine) {
836+
if (selectionStartLine == selectionEndLine) {
843837
x1 = textArea._offsetToX(line, selectionStart - lineStart);
844838
x2 = textArea._offsetToX(line, selectionEnd - lineStart);
845839
} else if(line == selectionStartLine) {

0 commit comments

Comments
 (0)