FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix to comment/uncomment to not toggle the last line, also renaming · botbit/processing@f2138aa · GitHub

Repository navigation

Commit f2138aa

Browse files
committed
fix to comment/uncomment to not toggle the last line, also renaming
start/end methods to start/stop
1 parent dcd41ae commit f2138aa

9 files changed

Lines changed: 66 additions & 165 deletions

File tree

‎app/src/processing/app/Editor.java‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,22 @@ public void actionPerformed(ActionEvent e) {
859859
public void actionPerformed(ActionEvent e) {
860860
beginCompoundEdit();
861861

862-
//textarea.selectAll();
863862
int startLine = textarea.getSelectionStartLine();
864-
int stopLine = textarea.getSelectionEndLine();
863+
int stopLine = textarea.getSelectionStopLine();
864+
865+
// If the selection ends at the beginning of the last line,
866+
// then don't (un)comment that line.
867+
int lastLineStart = textarea.getLineStartOffset(stopLine);
868+
int selectionStop = textarea.getSelectionStop();
869+
if (selectionStop == lastLineStart) {
870+
stopLine--;
871+
}
872+
873+
// If the text is empty, ignore the user.
865874
int length = textarea.getDocumentLength();
866875
int pos = textarea.getLineStartOffset(startLine);
867-
//System.out.println("pos is " + pos + " and line is " + startLine);
868-
//System.out.println("doc length is " + length);
869876
if (pos + 2 > length) return;
870-
877+
// Check the first two characters to see if it's already a comment.
871878
String begin = textarea.getText(pos, 2);
872879
//System.out.println("begin is '" + begin + "'");
873880
boolean commented = begin.equals("//");
@@ -885,12 +892,11 @@ public void actionPerformed(ActionEvent e) {
885892
textarea.select(location, location);
886893
textarea.setSelectedText("//");
887894
}
888-
//System.out.println(line);
889895
}
890896
// Subtract one from the end, otherwise selects past the current line.
891897
// (Which causes subsequent calls to keep expanding the selection)
892898
textarea.select(textarea.getLineStartOffset(startLine),
893-
textarea.getLineEndOffset(stopLine) - 1);
899+
textarea.getLineStopOffset(stopLine) - 1);
894900
endCompoundEdit();
895901
}
896902
});
@@ -1068,17 +1074,17 @@ public void setText(String what) {
10681074
* Called to update the text but not switch to a different
10691075
* set of code (which would affect the undo manager).
10701076
*/
1071-
public void setText(String what, int selectionStart, int selectionEnd) {
1077+
public void setText(String what, int selectionStart, int selectionStop) {
10721078
beginCompoundEdit();
10731079
textarea.setText(what);
10741080
endCompoundEdit();
10751081

10761082
// make sure that a tool isn't asking for a bad location
10771083
selectionStart =
10781084
Math.max(0, Math.min(selectionStart, textarea.getDocumentLength()));
1079-
selectionEnd =
1085+
selectionStop =
10801086
Math.max(0, Math.min(selectionStart, textarea.getDocumentLength()));
1081-
textarea.select(selectionStart, selectionEnd);
1087+
textarea.select(selectionStart, selectionStop);
10821088

10831089
textarea.requestFocus(); // get the caret blinking
10841090
}
@@ -1872,7 +1878,7 @@ public void highlightLine(int line) {
18721878
}
18731879
}
18741880
textarea.select(textarea.getLineStartOffset(line),
1875-
textarea.getLineEndOffset(line) - 1);
1881+
textarea.getLineStopOffset(line) - 1);
18761882
}
18771883

18781884

‎app/src/processing/app/EditorListener.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public boolean keyPressed(KeyEvent event) {
368368
if (spaceCount < 0) {
369369
// for rev 0122, actually delete extra space
370370
//textarea.setSelectionStart(origIndex + 1);
371-
textarea.setSelectionEnd(textarea.getSelectionEnd() - spaceCount);
371+
textarea.setSelectionEnd(textarea.getSelectionStop() - spaceCount);
372372
textarea.setSelectedText("\n");
373373
} else {
374374
String insertion = "\n" + Editor.EMPTY.substring(0, spaceCount);
@@ -403,7 +403,7 @@ public boolean keyPressed(KeyEvent event) {
403403
// first remove anything that was there (in case this multiple
404404
// characters are selected, so that it's not in the way of the
405405
// spaces for the auto-indent
406-
if (textarea.getSelectionStart() != textarea.getSelectionEnd()) {
406+
if (textarea.getSelectionStart() != textarea.getSelectionStop()) {
407407
textarea.setSelectedText("");
408408
}
409409

‎app/src/processing/app/FindReplace.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void find(boolean wrap) {
282282
}
283283

284284
//int selectionStart = editor.textarea.getSelectionStart();
285-
int selectionEnd = editor.textarea.getSelectionEnd();
285+
int selectionEnd = editor.textarea.getSelectionStop();
286286

287287
int nextIndex = text.indexOf(search, selectionEnd);
288288
if (nextIndex == -1) {

‎app/src/processing/app/Sketch.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public void nameCode(String newName) {
520520
editor.handleOpenUnchecked(mainFilename,
521521
currentIndex,
522522
editor.textarea.getSelectionStart(),
523-
editor.textarea.getSelectionEnd(),
523+
editor.textarea.getSelectionStop(),
524524
editor.textarea.getScrollPosition());
525525

526526
// get the changes into the sketchbook menu
@@ -974,7 +974,7 @@ public boolean saveAs() throws IOException {
974974
editor.handleOpenUnchecked(newFile.getPath(),
975975
currentIndex,
976976
editor.textarea.getSelectionStart(),
977-
editor.textarea.getSelectionEnd(),
977+
editor.textarea.getSelectionStop(),
978978
editor.textarea.getScrollPosition());
979979

980980
// Name changed, rebuild the sketch menus
@@ -1197,7 +1197,7 @@ public void setCurrent(int which) {
11971197
if (current != null) {
11981198
current.program = editor.getText();
11991199
current.selectionStart = editor.textarea.getSelectionStart();
1200-
current.selectionStop = editor.textarea.getSelectionEnd();
1200+
current.selectionStop = editor.textarea.getSelectionStop();
12011201
current.scrollPosition = editor.textarea.getScrollPosition();
12021202
}
12031203

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public void actionPerformed(ActionEvent evt)
407407
}
408408

409409
if(textArea.getSelectionStart()
410-
!= textArea.getSelectionEnd())
410+
!= textArea.getSelectionStop())
411411
{
412412
textArea.setSelectedText("");
413413
}
@@ -437,7 +437,7 @@ public void actionPerformed(ActionEvent evt)
437437
{
438438
JEditTextArea textArea = getTextArea(evt);
439439
int start = textArea.getSelectionStart();
440-
if(start != textArea.getSelectionEnd())
440+
if(start != textArea.getSelectionStop())
441441
{
442442
textArea.setSelectedText("");
443443
}
@@ -490,7 +490,7 @@ public void actionPerformed(ActionEvent evt)
490490
}
491491

492492
if(textArea.getSelectionStart()
493-
!= textArea.getSelectionEnd())
493+
!= textArea.getSelectionStop())
494494
{
495495
textArea.setSelectedText("");
496496
}
@@ -520,7 +520,7 @@ public void actionPerformed(ActionEvent evt)
520520
{
521521
JEditTextArea textArea = getTextArea(evt);
522522
int start = textArea.getSelectionStart();
523-
if(start != textArea.getSelectionEnd())
523+
if(start != textArea.getSelectionStop())
524524
{
525525
textArea.setSelectedText("");
526526
}
@@ -574,7 +574,7 @@ public void actionPerformed(ActionEvent evt)
574574

575575
int caret = textArea.getCaretPosition();
576576

577-
int lastOfLine = textArea.getLineEndOffset(
577+
int lastOfLine = textArea.getLineStopOffset(
578578
textArea.getCaretLine()) - 1;
579579
int lastVisibleLine = textArea.getFirstLine()
580580
+ textArea.getVisibleLines();
@@ -586,7 +586,7 @@ public void actionPerformed(ActionEvent evt)
586586
else
587587
lastVisibleLine -= (textArea.getElectricScroll() + 1);
588588

589-
int lastVisible = textArea.getLineEndOffset(lastVisibleLine) - 1;
589+
int lastVisible = textArea.getLineStopOffset(lastVisibleLine) - 1;
590590
int lastDocument = textArea.getDocumentLength();
591591

592592
if(caret == lastDocument)
@@ -746,7 +746,7 @@ public void actionPerformed(ActionEvent evt)
746746
if(caret == textArea.getDocumentLength())
747747
{
748748
if (textArea.getSelectionStart() !=
749-
textArea.getSelectionEnd()) {
749+
textArea.getSelectionStop()) {
750750
// just move to the end of the selection
751751
textArea.select(caret, caret);
752752
} else {
@@ -759,7 +759,7 @@ public void actionPerformed(ActionEvent evt)
759759

760760
} else {
761761
int start = textArea.getSelectionStart();
762-
int end = textArea.getSelectionEnd();
762+
int end = textArea.getSelectionStop();
763763
if (start != end) {
764764
textArea.select(end, end);
765765
} else {
@@ -923,7 +923,7 @@ public void actionPerformed(ActionEvent evt)
923923
textArea.select(textArea.getMarkPosition(), caret-1);
924924
} else {
925925
int start = textArea.getSelectionStart();
926-
int end = textArea.getSelectionEnd();
926+
int end = textArea.getSelectionStop();
927927
if (start != end) {
928928
textArea.select(start, start);
929929
} else {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ public int getLineStartOffset(int line)
841841
* @return The end offset of the specified line, or -1 if the line is
842842
* invalid.
843843
*/
844-
public int getLineEndOffset(int line)
844+
public int getLineStopOffset(int line)
845845
{
846846
Element lineElement = document.getDefaultRootElement()
847847
.getElement(line);
@@ -949,7 +949,7 @@ public final void getText(int start, int len, Segment segment)
949949
public final String getLineText(int lineIndex)
950950
{
951951
int start = getLineStartOffset(lineIndex);
952-
return getText(start,getLineEndOffset(lineIndex) - start - 1);
952+
return getText(start,getLineStopOffset(lineIndex) - start - 1);
953953
}
954954

955955
/**
@@ -960,7 +960,7 @@ public final String getLineText(int lineIndex)
960960
public final void getLineText(int lineIndex, Segment segment)
961961
{
962962
int start = getLineStartOffset(lineIndex);
963-
getText(start,getLineEndOffset(lineIndex) - start - 1,segment);
963+
getText(start,getLineStopOffset(lineIndex) - start - 1,segment);
964964
}
965965

966966
/**
@@ -1016,7 +1016,7 @@ public final void setSelectionStart(int selectionStart)
10161016
/**
10171017
* Returns the selection end offset.
10181018
*/
1019-
public final int getSelectionEnd()
1019+
public final int getSelectionStop()
10201020
{
10211021
return selectionEnd;
10221022
}
@@ -1041,13 +1041,13 @@ else if(rectSelect)
10411041
return Math.min(lineEnd,lineStart + end);
10421042
}
10431043
else
1044-
return getLineEndOffset(line) - 1;
1044+
return getLineStopOffset(line) - 1;
10451045
}
10461046

10471047
/**
10481048
* Returns the selection end line.
10491049
*/
1050-
public final int getSelectionEndLine()
1050+
public final int getSelectionStopLine()
10511051
{
10521052
return selectionEndLine;
10531053
}
@@ -1447,7 +1447,7 @@ public void overwriteSetSelectedText(String str)
14471447
// Don't overstrike if we're on the end of
14481448
// the line
14491449
int caret = getCaretPosition();
1450-
int caretLineEnd = getLineEndOffset(getCaretLine());
1450+
int caretLineEnd = getLineStopOffset(getCaretLine());
14511451
if(caretLineEnd - caret <= str.length())
14521452
{
14531453
setSelectedText(str);
@@ -2228,7 +2228,7 @@ private void doDoubleClick(MouseEvent evt, int line,
22282228
private void doTripleClick(MouseEvent evt, int line,
22292229
int offset, int dot)
22302230
{
2231-
select(getLineStartOffset(line),getLineEndOffset(line)-1);
2231+
select(getLineStartOffset(line),getLineStopOffset(line)-1);
22322232
}
22332233
}
22342234

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public final void invalidateLineRange(int firstLine, int lastLine)
464464
public final void invalidateSelectedLines()
465465
{
466466
invalidateLineRange(textArea.getSelectionStartLine(),
467-
textArea.getSelectionEndLine());
467+
textArea.getSelectionStopLine());
468468
}
469469

470470
/**
@@ -633,7 +633,7 @@ protected void paintHighlight(Graphics gfx, int line, int y)
633633
{
634634
if (!printing) {
635635
if (line >= textArea.getSelectionStartLine()
636-
&& line <= textArea.getSelectionEndLine())
636+
&& line <= textArea.getSelectionStopLine())
637637
paintLineHighlight(gfx,line,y);
638638

639639
if (highlights != null)
@@ -653,7 +653,7 @@ protected void paintLineHighlight(Graphics gfx, int line, int y)
653653
y += fm.getLeading() + fm.getMaxDescent();
654654

655655
int selectionStart = textArea.getSelectionStart();
656-
int selectionEnd = textArea.getSelectionEnd();
656+
int selectionEnd = textArea.getSelectionStop();
657657

658658
if (selectionStart == selectionEnd) {
659659
if (lineHighlight) {
@@ -664,7 +664,7 @@ protected void paintLineHighlight(Graphics gfx, int line, int y)
664664
gfx.setColor(selectionColor);
665665

666666
int selectionStartLine = textArea.getSelectionStartLine();
667-
int selectionEndLine = textArea.getSelectionEndLine();
667+
int selectionEndLine = textArea.getSelectionStopLine();
668668
int lineStart = textArea.getLineStartOffset(line);
669669

670670
int x1, x2;

‎app/src/processing/app/tools/AutoFormat.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ else if(tabs > 0)
900900
*/
901901

902902
// save current (rough) selection point
903-
int selectionEnd = editor.textarea.getSelectionEnd();
903+
int selectionEnd = editor.textarea.getSelectionStop();
904904

905905
// make sure the caret would be past the end of the text
906906
if (strOut.length() < selectionEnd - 1) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL