Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/processing/app/syntax/DefaultInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void addDefaultKeyBindings()
addKeyBinding("TAB",INSERT_TAB);

addKeyBinding("INSERT",OVERWRITE);
addKeyBinding("C+\\",TOGGLE_RECT);

addKeyBinding("HOME",HOME);
addKeyBinding("END",END);
Expand Down
10 changes: 0 additions & 10 deletions app/src/processing/app/syntax/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public abstract class InputHandler extends KeyAdapter
public static final ActionListener SELECT_PREV_PAGE = new prev_page(true);
public static final ActionListener SELECT_PREV_WORD = new prev_word(true);
public static final ActionListener REPEAT = new repeat();
public static final ActionListener TOGGLE_RECT = new toggle_rect();
public static final ActionListener CLIPBOARD_CUT = new clipboard_cut(); // [fry]
public static final ActionListener CLIPBOARD_COPY = new clipboard_copy();
public static final ActionListener CLIPBOARD_PASTE = new clipboard_paste();
Expand Down Expand Up @@ -133,7 +132,6 @@ public abstract class InputHandler extends KeyAdapter
actions.put("select-prev-page",SELECT_PREV_PAGE);
actions.put("select-prev-word",SELECT_PREV_WORD);
actions.put("repeat",REPEAT);
actions.put("toggle-rect",TOGGLE_RECT);
actions.put("insert-char",INSERT_CHAR);
actions.put("clipboard-cut",CLIPBOARD_CUT);
actions.put("clipboard-copy",CLIPBOARD_COPY);
Expand Down Expand Up @@ -1060,14 +1058,6 @@ public void actionPerformed(ActionEvent evt) {
}


public static class toggle_rect implements ActionListener {
public void actionPerformed(ActionEvent evt) {
JEditTextArea textArea = getTextArea(evt);
textArea.setSelectionRectangular(!textArea.isSelectionRectangular());
}
}


public static class clipboard_cut implements ActionListener {
public void actionPerformed(ActionEvent evt) {
getTextArea(evt).cut();
Expand Down
154 changes: 9 additions & 145 deletions app/src/processing/app/syntax/JEditTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -1072,19 +1072,8 @@ public final int getSelectionStart() {
*/
public int getSelectionStart(int line)
{
if(line == selectionStartLine)
if (line == selectionStartLine)
return selectionStart;
else if(rectSelect)
{
Element map = document.getDefaultRootElement();
int start = selectionStart - map.getElement(selectionStartLine)
.getStartOffset();

Element lineElement = map.getElement(line);
int lineStart = lineElement.getStartOffset();
int lineEnd = lineElement.getEndOffset() - 1;
return Math.min(lineEnd,lineStart + start);
}
else
return getLineStartOffset(line);
}
Expand Down Expand Up @@ -1122,19 +1111,8 @@ public final int getSelectionStop()
*/
public int getSelectionStop(int line)
{
if(line == selectionEndLine)
if (line == selectionEndLine)
return selectionEnd;
else if(rectSelect)
{
Element map = document.getDefaultRootElement();
int end = selectionEnd - map.getElement(selectionEndLine)
.getStartOffset();

Element lineElement = map.getElement(line);
int lineStart = lineElement.getStartOffset();
int lineEnd = lineElement.getEndOffset() - 1;
return Math.min(lineEnd,lineStart + end);
}
else
return getLineStopOffset(line) - 1;
}
Expand Down Expand Up @@ -1297,10 +1275,6 @@ public void select(int start, int end)
caretTimer.restart();
}

// Disable rectangle select if selection start = selection end
if(selectionStart == selectionEnd)
rectSelect = false;

// Clear the `magic' caret position used by up/down
magicCaret = -1;

Expand Down Expand Up @@ -1380,54 +1354,10 @@ protected void setNewSelectionWord( int line, int offset )
*/
public final String getSelectedText()
{
if(selectionStart == selectionEnd)
if (selectionStart == selectionEnd) {
return null;

if(rectSelect)
{
// Return each row of the selection on a new line

Element map = document.getDefaultRootElement();

int start = selectionStart - map.getElement(selectionStartLine)
.getStartOffset();
int end = selectionEnd - map.getElement(selectionEndLine)
.getStartOffset();

// Certain rectangles satisfy this condition...
if(end < start)
{
int tmp = end;
end = start;
start = tmp;
}

StringBuilder sb = new StringBuilder();
Segment seg = new Segment();

for(int i = selectionStartLine; i <= selectionEndLine; i++)
{
Element lineElement = map.getElement(i);
int lineStart = lineElement.getStartOffset();
int lineEnd = lineElement.getEndOffset() - 1;
int lineLen = lineEnd - lineStart;

lineStart = Math.min(lineStart + start,lineEnd);
lineLen = Math.min(end - start,lineEnd - lineStart);

getText(lineStart,lineLen,seg);
sb.append(seg.array,seg.offset,seg.count);

if(i != selectionEndLine)
sb.append('\n');
}

return sb.toString();
}
else
{
return getText(selectionStart,
selectionEnd - selectionStart);
} else {
return getText(selectionStart, selectionEnd - selectionStart);
}
}

Expand Down Expand Up @@ -1456,55 +1386,11 @@ public void setSelectedText(String selectedText, boolean recordCompoundEdit) {
}

try {
if (rectSelect) {
Element map = document.getDefaultRootElement();

int start = selectionStart -
map.getElement(selectionStartLine).getStartOffset();
int end = selectionEnd -
map.getElement(selectionEndLine).getStartOffset();

// Certain rectangles satisfy this condition...
if (end < start) {
int tmp = end;
end = start;
start = tmp;
}

int lastNewline = 0;
int currNewline = 0;

for (int i = selectionStartLine; i <= selectionEndLine; i++) {
Element lineElement = map.getElement(i);
int lineStart = lineElement.getStartOffset();
int lineEnd = lineElement.getEndOffset() - 1;
int rectStart = Math.min(lineEnd,lineStart + start);

document.remove(rectStart,Math.min(lineEnd - rectStart, end - start));

if (selectedText != null) {
currNewline = selectedText.indexOf('\n', lastNewline);
if (currNewline == -1) {
currNewline = selectedText.length();
}
document.insertString(rectStart, selectedText.substring(lastNewline, currNewline), null);
lastNewline = Math.min(selectedText.length(), currNewline + 1);
}
}

if (selectedText != null &&
currNewline != selectedText.length()) {
int offset = map.getElement(selectionEndLine).getEndOffset() - 1;
document.insertString(offset, "\n", null);
document.insertString(offset + 1,selectedText.substring(currNewline + 1), null);
}
} else {
document.remove(selectionStart, selectionEnd - selectionStart);
if (selectedText != null) {
document.insertString(selectionStart, selectedText,null);
}
document.remove(selectionStart, selectionEnd - selectionStart);
if (selectedText != null) {
document.insertString(selectionStart, selectedText,null);
}
} catch(BadLocationException bl) {
} catch (BadLocationException bl) {
bl.printStackTrace();
throw new InternalError("Cannot replace selection");

Expand Down Expand Up @@ -1632,24 +1518,6 @@ public final void setOverwriteEnabled(boolean overwrite)
painter.invalidateSelectedLines();
}

/**
* Returns true if the selection is rectangular, false otherwise.
*/
public final boolean isSelectionRectangular()
{
return rectSelect;
}

/**
* Sets if the selection should be rectangular.
* @param rectSelect True if the selection should be rectangular,
* false otherwise.
*/
public final void setSelectionRectangular(boolean rectSelect)
{
this.rectSelect = rectSelect;
painter.invalidateSelectedLines();
}

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

protected int magicCaret;
protected boolean overwrite;
protected boolean rectSelect;


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

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

private void doSingleClick(MouseEvent evt, int line, int offset, int dot) {
if ((evt.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
rectSelect = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0;
select(getMarkPosition(),dot);
} else {
setCaretPosition(dot);
Expand Down
8 changes: 1 addition & 7 deletions app/src/processing/app/syntax/TextAreaPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,7 @@ protected void paintLineHighlight(Graphics gfx, int line, int y) {
int lineStart = textArea.getLineStartOffset(line);

int x1, x2;
if (textArea.isSelectionRectangular()) {
int lineLen = textArea.getLineLength(line);
x1 = textArea._offsetToX(line,Math.min(lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine)));
x2 = textArea._offsetToX(line,Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine)));
if (x1 == x2)
x2++;
} else if(selectionStartLine == selectionEndLine) {
if (selectionStartLine == selectionEndLine) {
x1 = textArea._offsetToX(line, selectionStart - lineStart);
x2 = textArea._offsetToX(line, selectionEnd - lineStart);
} else if(line == selectionStartLine) {
Expand Down