| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -859,15 +859,22 @@ public void actionPerformed(ActionEvent e) { | |||
| 859 | 859 | public void actionPerformed(ActionEvent e) { | |
| 860 | 860 | beginCompoundEdit(); | |
| 861 | 861 | ||
| 862 | - //textarea.selectAll(); | ||
| 863 | 862 | 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. | ||
| 865 | 874 | int length = textarea.getDocumentLength(); | |
| 866 | 875 | int pos = textarea.getLineStartOffset(startLine); | |
| 867 | - //System.out.println("pos is " + pos + " and line is " + startLine); | ||
| 868 | - //System.out.println("doc length is " + length); | ||
| 869 | 876 | if (pos + 2 > length) return; | |
| 870 | - | ||
| 877 | + // Check the first two characters to see if it's already a comment. | ||
| 871 | 878 | String begin = textarea.getText(pos, 2); | |
| 872 | 879 | //System.out.println("begin is '" + begin + "'"); | |
| 873 | 880 | boolean commented = begin.equals("//"); | |
@@ -885,12 +892,11 @@ public void actionPerformed(ActionEvent e) { | |||
| 885 | 892 | textarea.select(location, location); | |
| 886 | 893 | textarea.setSelectedText("//"); | |
| 887 | 894 | } | |
| 888 | - //System.out.println(line); | ||
| 889 | 895 | } | |
| 890 | 896 | // Subtract one from the end, otherwise selects past the current line. | |
| 891 | 897 | // (Which causes subsequent calls to keep expanding the selection) | |
| 892 | 898 | textarea.select(textarea.getLineStartOffset(startLine), | |
| 893 | - textarea.getLineEndOffset(stopLine) - 1); | ||
| 899 | + textarea.getLineStopOffset(stopLine) - 1); | ||
| 894 | 900 | endCompoundEdit(); | |
| 895 | 901 | } | |
| 896 | 902 | }); | |
@@ -1068,17 +1074,17 @@ public void setText(String what) { | |||
| 1068 | 1074 | * Called to update the text but not switch to a different | |
| 1069 | 1075 | * set of code (which would affect the undo manager). | |
| 1070 | 1076 | */ | |
| 1071 | - public void setText(String what, int selectionStart, int selectionEnd) { | ||
| 1077 | + public void setText(String what, int selectionStart, int selectionStop) { | ||
| 1072 | 1078 | beginCompoundEdit(); | |
| 1073 | 1079 | textarea.setText(what); | |
| 1074 | 1080 | endCompoundEdit(); | |
| 1075 | 1081 | ||
| 1076 | 1082 | // make sure that a tool isn't asking for a bad location | |
| 1077 | 1083 | selectionStart = | |
| 1078 | 1084 | Math.max(0, Math.min(selectionStart, textarea.getDocumentLength())); | |
| 1079 | - selectionEnd = | ||
| 1085 | + selectionStop = | ||
| 1080 | 1086 | Math.max(0, Math.min(selectionStart, textarea.getDocumentLength())); | |
| 1081 | - textarea.select(selectionStart, selectionEnd); | ||
| 1087 | + textarea.select(selectionStart, selectionStop); | ||
| 1082 | 1088 | ||
| 1083 | 1089 | textarea.requestFocus(); // get the caret blinking | |
| 1084 | 1090 | } | |
@@ -1872,7 +1878,7 @@ public void highlightLine(int line) { | |||
| 1872 | 1878 | } | |
| 1873 | 1879 | } | |
| 1874 | 1880 | textarea.select(textarea.getLineStartOffset(line), | |
| 1875 | - textarea.getLineEndOffset(line) - 1); | ||
| 1881 | + textarea.getLineStopOffset(line) - 1); | ||
| 1876 | 1882 | } | |
| 1877 | 1883 | ||
| 1878 | 1884 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -368,7 +368,7 @@ public boolean keyPressed(KeyEvent event) { | |||
| 368 | 368 | if (spaceCount < 0) { | |
| 369 | 369 | // for rev 0122, actually delete extra space | |
| 370 | 370 | //textarea.setSelectionStart(origIndex + 1); | |
| 371 | - textarea.setSelectionEnd(textarea.getSelectionEnd() - spaceCount); | ||
| 371 | + textarea.setSelectionEnd(textarea.getSelectionStop() - spaceCount); | ||
| 372 | 372 | textarea.setSelectedText("\n"); | |
| 373 | 373 | } else { | |
| 374 | 374 | String insertion = "\n" + Editor.EMPTY.substring(0, spaceCount); | |
@@ -403,7 +403,7 @@ public boolean keyPressed(KeyEvent event) { | |||
| 403 | 403 | // first remove anything that was there (in case this multiple | |
| 404 | 404 | // characters are selected, so that it's not in the way of the | |
| 405 | 405 | // spaces for the auto-indent | |
| 406 | - if (textarea.getSelectionStart() != textarea.getSelectionEnd()) { | ||
| 406 | + if (textarea.getSelectionStart() != textarea.getSelectionStop()) { | ||
| 407 | 407 | textarea.setSelectedText(""); | |
| 408 | 408 | } | |
| 409 | 409 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -282,7 +282,7 @@ public void find(boolean wrap) { | |||
| 282 | 282 | } | |
| 283 | 283 | ||
| 284 | 284 | //int selectionStart = editor.textarea.getSelectionStart(); | |
| 285 | - int selectionEnd = editor.textarea.getSelectionEnd(); | ||
| 285 | + int selectionEnd = editor.textarea.getSelectionStop(); | ||
| 286 | 286 | ||
| 287 | 287 | int nextIndex = text.indexOf(search, selectionEnd); | |
| 288 | 288 | if (nextIndex == -1) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -520,7 +520,7 @@ public void nameCode(String newName) { | |||
| 520 | 520 | editor.handleOpenUnchecked(mainFilename, | |
| 521 | 521 | currentIndex, | |
| 522 | 522 | editor.textarea.getSelectionStart(), | |
| 523 | - editor.textarea.getSelectionEnd(), | ||
| 523 | + editor.textarea.getSelectionStop(), | ||
| 524 | 524 | editor.textarea.getScrollPosition()); | |
| 525 | 525 | ||
| 526 | 526 | // get the changes into the sketchbook menu | |
@@ -974,7 +974,7 @@ public boolean saveAs() throws IOException { | |||
| 974 | 974 | editor.handleOpenUnchecked(newFile.getPath(), | |
| 975 | 975 | currentIndex, | |
| 976 | 976 | editor.textarea.getSelectionStart(), | |
| 977 | - editor.textarea.getSelectionEnd(), | ||
| 977 | + editor.textarea.getSelectionStop(), | ||
| 978 | 978 | editor.textarea.getScrollPosition()); | |
| 979 | 979 | ||
| 980 | 980 | // Name changed, rebuild the sketch menus | |
@@ -1197,7 +1197,7 @@ public void setCurrent(int which) { | |||
| 1197 | 1197 | if (current != null) { | |
| 1198 | 1198 | current.program = editor.getText(); | |
| 1199 | 1199 | current.selectionStart = editor.textarea.getSelectionStart(); | |
| 1200 | - current.selectionStop = editor.textarea.getSelectionEnd(); | ||
| 1200 | + current.selectionStop = editor.textarea.getSelectionStop(); | ||
| 1201 | 1201 | current.scrollPosition = editor.textarea.getScrollPosition(); | |
| 1202 | 1202 | } | |
| 1203 | 1203 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -407,7 +407,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 407 | 407 | } | |
| 408 | 408 | ||
| 409 | 409 | if(textArea.getSelectionStart() | |
| 410 | - != textArea.getSelectionEnd()) | ||
| 410 | + != textArea.getSelectionStop()) | ||
| 411 | 411 | { | |
| 412 | 412 | textArea.setSelectedText(""); | |
| 413 | 413 | } | |
@@ -437,7 +437,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 437 | 437 | { | |
| 438 | 438 | JEditTextArea textArea = getTextArea(evt); | |
| 439 | 439 | int start = textArea.getSelectionStart(); | |
| 440 | - if(start != textArea.getSelectionEnd()) | ||
| 440 | + if(start != textArea.getSelectionStop()) | ||
| 441 | 441 | { | |
| 442 | 442 | textArea.setSelectedText(""); | |
| 443 | 443 | } | |
@@ -490,7 +490,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 490 | 490 | } | |
| 491 | 491 | ||
| 492 | 492 | if(textArea.getSelectionStart() | |
| 493 | - != textArea.getSelectionEnd()) | ||
| 493 | + != textArea.getSelectionStop()) | ||
| 494 | 494 | { | |
| 495 | 495 | textArea.setSelectedText(""); | |
| 496 | 496 | } | |
@@ -520,7 +520,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 520 | 520 | { | |
| 521 | 521 | JEditTextArea textArea = getTextArea(evt); | |
| 522 | 522 | int start = textArea.getSelectionStart(); | |
| 523 | - if(start != textArea.getSelectionEnd()) | ||
| 523 | + if(start != textArea.getSelectionStop()) | ||
| 524 | 524 | { | |
| 525 | 525 | textArea.setSelectedText(""); | |
| 526 | 526 | } | |
@@ -574,7 +574,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 574 | 574 | ||
| 575 | 575 | int caret = textArea.getCaretPosition(); | |
| 576 | 576 | ||
| 577 | - int lastOfLine = textArea.getLineEndOffset( | ||
| 577 | + int lastOfLine = textArea.getLineStopOffset( | ||
| 578 | 578 | textArea.getCaretLine()) - 1; | |
| 579 | 579 | int lastVisibleLine = textArea.getFirstLine() | |
| 580 | 580 | + textArea.getVisibleLines(); | |
@@ -586,7 +586,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 586 | 586 | else | |
| 587 | 587 | lastVisibleLine -= (textArea.getElectricScroll() + 1); | |
| 588 | 588 | ||
| 589 | - int lastVisible = textArea.getLineEndOffset(lastVisibleLine) - 1; | ||
| 589 | + int lastVisible = textArea.getLineStopOffset(lastVisibleLine) - 1; | ||
| 590 | 590 | int lastDocument = textArea.getDocumentLength(); | |
| 591 | 591 | ||
| 592 | 592 | if(caret == lastDocument) | |
@@ -746,7 +746,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 746 | 746 | if(caret == textArea.getDocumentLength()) | |
| 747 | 747 | { | |
| 748 | 748 | if (textArea.getSelectionStart() != | |
| 749 | - textArea.getSelectionEnd()) { | ||
| 749 | + textArea.getSelectionStop()) { | ||
| 750 | 750 | // just move to the end of the selection | |
| 751 | 751 | textArea.select(caret, caret); | |
| 752 | 752 | } else { | |
@@ -759,7 +759,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 759 | 759 | ||
| 760 | 760 | } else { | |
| 761 | 761 | int start = textArea.getSelectionStart(); | |
| 762 | - int end = textArea.getSelectionEnd(); | ||
| 762 | + int end = textArea.getSelectionStop(); | ||
| 763 | 763 | if (start != end) { | |
| 764 | 764 | textArea.select(end, end); | |
| 765 | 765 | } else { | |
@@ -923,7 +923,7 @@ public void actionPerformed(ActionEvent evt) | |||
| 923 | 923 | textArea.select(textArea.getMarkPosition(), caret-1); | |
| 924 | 924 | } else { | |
| 925 | 925 | int start = textArea.getSelectionStart(); | |
| 926 | - int end = textArea.getSelectionEnd(); | ||
| 926 | + int end = textArea.getSelectionStop(); | ||
| 927 | 927 | if (start != end) { | |
| 928 | 928 | textArea.select(start, start); | |
| 929 | 929 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -841,7 +841,7 @@ public int getLineStartOffset(int line) | |||
| 841 | 841 | * @return The end offset of the specified line, or -1 if the line is | |
| 842 | 842 | * invalid. | |
| 843 | 843 | */ | |
| 844 | - public int getLineEndOffset(int line) | ||
| 844 | + public int getLineStopOffset(int line) | ||
| 845 | 845 | { | |
| 846 | 846 | Element lineElement = document.getDefaultRootElement() | |
| 847 | 847 | .getElement(line); | |
@@ -949,7 +949,7 @@ public final void getText(int start, int len, Segment segment) | |||
| 949 | 949 | public final String getLineText(int lineIndex) | |
| 950 | 950 | { | |
| 951 | 951 | int start = getLineStartOffset(lineIndex); | |
| 952 | - return getText(start,getLineEndOffset(lineIndex) - start - 1); | ||
| 952 | + return getText(start,getLineStopOffset(lineIndex) - start - 1); | ||
| 953 | 953 | } | |
| 954 | 954 | ||
| 955 | 955 | /** | |
@@ -960,7 +960,7 @@ public final String getLineText(int lineIndex) | |||
| 960 | 960 | public final void getLineText(int lineIndex, Segment segment) | |
| 961 | 961 | { | |
| 962 | 962 | int start = getLineStartOffset(lineIndex); | |
| 963 | - getText(start,getLineEndOffset(lineIndex) - start - 1,segment); | ||
| 963 | + getText(start,getLineStopOffset(lineIndex) - start - 1,segment); | ||
| 964 | 964 | } | |
| 965 | 965 | ||
| 966 | 966 | /** | |
@@ -1016,7 +1016,7 @@ public final void setSelectionStart(int selectionStart) | |||
| 1016 | 1016 | /** | |
| 1017 | 1017 | * Returns the selection end offset. | |
| 1018 | 1018 | */ | |
| 1019 | - public final int getSelectionEnd() | ||
| 1019 | + public final int getSelectionStop() | ||
| 1020 | 1020 | { | |
| 1021 | 1021 | return selectionEnd; | |
| 1022 | 1022 | } | |
@@ -1041,13 +1041,13 @@ else if(rectSelect) | |||
| 1041 | 1041 | return Math.min(lineEnd,lineStart + end); | |
| 1042 | 1042 | } | |
| 1043 | 1043 | else | |
| 1044 | - return getLineEndOffset(line) - 1; | ||
| 1044 | + return getLineStopOffset(line) - 1; | ||
| 1045 | 1045 | } | |
| 1046 | 1046 | ||
| 1047 | 1047 | /** | |
| 1048 | 1048 | * Returns the selection end line. | |
| 1049 | 1049 | */ | |
| 1050 | - public final int getSelectionEndLine() | ||
| 1050 | + public final int getSelectionStopLine() | ||
| 1051 | 1051 | { | |
| 1052 | 1052 | return selectionEndLine; | |
| 1053 | 1053 | } | |
@@ -1447,7 +1447,7 @@ public void overwriteSetSelectedText(String str) | |||
| 1447 | 1447 | // Don't overstrike if we're on the end of | |
| 1448 | 1448 | // the line | |
| 1449 | 1449 | int caret = getCaretPosition(); | |
| 1450 | - int caretLineEnd = getLineEndOffset(getCaretLine()); | ||
| 1450 | + int caretLineEnd = getLineStopOffset(getCaretLine()); | ||
| 1451 | 1451 | if(caretLineEnd - caret <= str.length()) | |
| 1452 | 1452 | { | |
| 1453 | 1453 | setSelectedText(str); | |
@@ -2228,7 +2228,7 @@ private void doDoubleClick(MouseEvent evt, int line, | |||
| 2228 | 2228 | private void doTripleClick(MouseEvent evt, int line, | |
| 2229 | 2229 | int offset, int dot) | |
| 2230 | 2230 | { | |
| 2231 | - select(getLineStartOffset(line),getLineEndOffset(line)-1); | ||
| 2231 | + select(getLineStartOffset(line),getLineStopOffset(line)-1); | ||
| 2232 | 2232 | } | |
| 2233 | 2233 | } | |
| 2234 | 2234 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -464,7 +464,7 @@ public final void invalidateLineRange(int firstLine, int lastLine) | |||
| 464 | 464 | public final void invalidateSelectedLines() | |
| 465 | 465 | { | |
| 466 | 466 | invalidateLineRange(textArea.getSelectionStartLine(), | |
| 467 | - textArea.getSelectionEndLine()); | ||
| 467 | + textArea.getSelectionStopLine()); | ||
| 468 | 468 | } | |
| 469 | 469 | ||
| 470 | 470 | /** | |
@@ -633,7 +633,7 @@ protected void paintHighlight(Graphics gfx, int line, int y) | |||
| 633 | 633 | { | |
| 634 | 634 | if (!printing) { | |
| 635 | 635 | if (line >= textArea.getSelectionStartLine() | |
| 636 | - && line <= textArea.getSelectionEndLine()) | ||
| 636 | + && line <= textArea.getSelectionStopLine()) | ||
| 637 | 637 | paintLineHighlight(gfx,line,y); | |
| 638 | 638 | ||
| 639 | 639 | if (highlights != null) | |
@@ -653,7 +653,7 @@ protected void paintLineHighlight(Graphics gfx, int line, int y) | |||
| 653 | 653 | y += fm.getLeading() + fm.getMaxDescent(); | |
| 654 | 654 | ||
| 655 | 655 | int selectionStart = textArea.getSelectionStart(); | |
| 656 | - int selectionEnd = textArea.getSelectionEnd(); | ||
| 656 | + int selectionEnd = textArea.getSelectionStop(); | ||
| 657 | 657 | ||
| 658 | 658 | if (selectionStart == selectionEnd) { | |
| 659 | 659 | if (lineHighlight) { | |
@@ -664,7 +664,7 @@ protected void paintLineHighlight(Graphics gfx, int line, int y) | |||
| 664 | 664 | gfx.setColor(selectionColor); | |
| 665 | 665 | ||
| 666 | 666 | int selectionStartLine = textArea.getSelectionStartLine(); | |
| 667 | - int selectionEndLine = textArea.getSelectionEndLine(); | ||
| 667 | + int selectionEndLine = textArea.getSelectionStopLine(); | ||
| 668 | 668 | int lineStart = textArea.getLineStartOffset(line); | |
| 669 | 669 | ||
| 670 | 670 | int x1, x2; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -900,7 +900,7 @@ else if(tabs > 0) | |||
| 900 | 900 | */ | |
| 901 | 901 | ||
| 902 | 902 | // save current (rough) selection point | |
| 903 | - int selectionEnd = editor.textarea.getSelectionEnd(); | ||
| 903 | + int selectionEnd = editor.textarea.getSelectionStop(); | ||
| 904 | 904 | ||
| 905 | 905 | // make sure the caret would be past the end of the text | |
| 906 | 906 | if (strOut.length() < selectionEnd - 1) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments