📄 jedittextarea.java
字号:
/** * Deselects everything. */ public void selectNone() { setSelection((Selection)null); } //}}} //{{{ setSelection() method /** * Sets the selection. Nested and overlapping selections are merged * where possible. * @param selection The new selection * since jEdit 3.2pre1 */ public void setSelection(Selection[] selection) { // invalidate the old selection invalidateSelectedLines(); this.selection.removeAllElements(); if(selection != null) { for(int i = 0; i < selection.length; i++) _addToSelection(selection[i]); } fireCaretEvent(); } //}}} //{{{ setSelection() method /** * Sets the selection. Nested and overlapping selections are merged * where possible. * @param selection The new selection * since jEdit 3.2pre1 */ public void setSelection(Selection selection) { invalidateSelectedLines(); this.selection.removeAllElements(); if(selection != null) _addToSelection(selection); fireCaretEvent(); } //}}} //{{{ addToSelection() method /** * Adds to the selection. Nested and overlapping selections are merged * where possible. * @param selection The new selection * since jEdit 3.2pre1 */ public void addToSelection(Selection[] selection) { if(selection != null) { for(int i = 0; i < selection.length; i++) _addToSelection(selection[i]); } // to hide current line highlight invalidateLine(caretLine); fireCaretEvent(); } //}}} //{{{ addToSelection() method /** * Adds to the selection. Nested and overlapping selections are merged * where possible. * @param selection The new selection * since jEdit 3.2pre1 */ public void addToSelection(Selection selection) { _addToSelection(selection); // to hide current line highlight invalidateLine(caretLine); fireCaretEvent(); } //}}} //{{{ getSelectionAtOffset() method /** * Returns the selection containing the specific offset, or <code>null</code> * if there is no selection at that offset. * @param offset The offset * @since jEdit 3.2pre1 */ public Selection getSelectionAtOffset(int offset) { if(selection != null) { for(int i = 0; i < selection.size(); i++) { Selection s = (Selection)selection.elementAt(i); if(offset >= s.start && offset <= s.end) return s; } } return null; } //}}} //{{{ removeFromSelection() method /** * Deactivates the specified selection. * @param s The selection * @since jEdit 3.2pre1 */ public void removeFromSelection(Selection sel) { selection.removeElement(sel); invalidateLineRange(sel.startLine,sel.endLine); // to hide current line highlight invalidateLine(caretLine); fireCaretEvent(); } //}}} //{{{ removeFromSelection() method /** * Deactivates the selection at the specified offset. If there is * no selection at that offset, does nothing. * @param offset The offset * @since jEdit 3.2pre1 */ public void removeFromSelection(int offset) { Selection sel = getSelectionAtOffset(offset); if(sel == null) return; selection.removeElement(sel); invalidateLineRange(sel.startLine,sel.endLine); // to hide current line highlight invalidateLine(caretLine); fireCaretEvent(); } //}}} //{{{ resizeSelection() method /** * Resizes the selection at the specified offset, or creates a new * one if there is no selection at the specified offset. This is a * utility method that is mainly useful in the mouse event handler * because it handles the case of end being before offset gracefully * (unlike the rest of the selection API). * @param offset The offset * @param end The new selection end * @param extraEndVirt Only for rectangular selections - specifies how * far it extends into virtual space. * @param rect Make the selection rectangular? * @since jEdit 3.2pre1 */ public void resizeSelection(int offset, int end, int extraEndVirt, boolean rect) { Selection s = getSelectionAtOffset(offset); if(s != null) { invalidateLineRange(s.startLine,s.endLine); selection.removeElement(s); } boolean reversed = false; if(end < offset) { int tmp = offset; offset = end; end = tmp; reversed = true; } Selection newSel; if(rect) { Selection.Rect rectSel = new Selection.Rect(offset,end); if(reversed) rectSel.extraStartVirt = extraEndVirt; else rectSel.extraEndVirt = extraEndVirt; newSel = rectSel; } else newSel = new Selection.Range(offset,end); _addToSelection(newSel); fireCaretEvent(); } //}}} //{{{ extendSelection() method /** * Extends the selection at the specified offset, or creates a new * one if there is no selection at the specified offset. This is * different from resizing in that the new chunk is added to the * selection in question, instead of replacing it. * @param offset The offset * @param end The new selection end * @since jEdit 3.2pre1 */ public void extendSelection(int offset, int end) { extendSelection(offset,end,0,0); } //}}} //{{{ extendSelection() method /** * Extends the selection at the specified offset, or creates a new * one if there is no selection at the specified offset. This is * different from resizing in that the new chunk is added to the * selection in question, instead of replacing it. * @param offset The offset * @param end The new selection end * @param extraStartVirt Extra virtual space at the start * @param extraEndVirt Extra virtual space at the end * @since jEdit 4.2pre1 */ public void extendSelection(int offset, int end, int extraStartVirt, int extraEndVirt) { Selection s = getSelectionAtOffset(offset); if(s != null) { invalidateLineRange(s.startLine,s.endLine); selection.removeElement(s); if(offset == s.start) { offset = end; end = s.end; } else if(offset == s.end) { offset = s.start; } } if(end < offset) { int tmp = end; end = offset; offset = tmp; } if(rectangularSelectionMode) { s = new Selection.Rect(offset,end); ((Selection.Rect)s).extraStartVirt = extraStartVirt; ((Selection.Rect)s).extraEndVirt = extraEndVirt; } else s = new Selection.Range(offset,end); _addToSelection(s); fireCaretEvent(); if(rectangularSelectionMode && extraEndVirt != 0) { int line = getLineOfOffset(end); scrollTo(line,getLineLength(line) + extraEndVirt,false); } } //}}} //{{{ getSelectedText() method /** * Returns the text in the specified selection. * @param s The selection * @since jEdit 3.2pre1 */ public String getSelectedText(Selection s) { StringBuffer buf = new StringBuffer(); s.getText(buffer,buf); return buf.toString(); } //}}} //{{{ getSelectedText() method /** * Returns the text in all active selections. * @param separator The string to insert between each text chunk * (for example, a newline) * @since jEdit 3.2pre1 */ public String getSelectedText(String separator) { if(selection.size() == 0) return null; StringBuffer buf = new StringBuffer(); for(int i = 0; i < selection.size(); i++) { if(i != 0) buf.append(separator); ((Selection)selection.elementAt(i)).getText(buffer,buf); } return buf.toString(); } //}}} //{{{ getSelectedText() method /** * Returns the text in all active selections, with a newline * between each text chunk. */ public String getSelectedText() { return getSelectedText("\n"); } //}}} //{{{ setSelectedText() method /** * Replaces the selection with the specified text. * @param s The selection * @param selectedText The new text * @since jEdit 3.2pre1 */ public void setSelectedText(Selection s, String selectedText) { if(!isEditable()) { throw new InternalError("Text component" + " read only"); } try { buffer.beginCompoundEdit(); moveCaretPosition(s.setText(buffer,selectedText)); } // No matter what happends... stops us from leaving buffer // in a bad state finally { buffer.endCompoundEdit(); } // no no no!!!! //selectNone(); } //}}} //{{{ setSelectedText() method /** * Replaces the selection at the caret with the specified text. * If there is no selection at the caret, the text is inserted at * the caret position. */ public void setSelectedText(String selectedText) { setSelectedText(selectedText,true); } //}}} //{{{ setSelectedText() method /** * Replaces the selection at the caret with the specified text. * If there is no selection at the caret, the text is inserted at * the caret position. * @param selectedText The new selection * @param moveCaret Move caret to insertion location if necessary * @since jEdit 4.2pre5 */ public void setSelectedText(String selectedText, boolean moveCaret) { if(!isEditable()) { throw new InternalError("Text component" + " read only"); } Selection[] selection = getSelection(); if(selection.length == 0) { // for compatibility with older jEdit versions buffer.insert(caret,selectedText); } else { try { int newCaret = -1; buffer.beginCompoundEdit(); for(int i = 0; i < selection.length; i++) { newCaret = selection[i].setText(buffer,selectedText); } if(moveCaret) moveCaretPosition(newCaret); } finally { buffer.endCompoundEdit(); } } selectNone(); } //}}} //{{{ getSelectedLines() method /** * Returns a sorted array of line numbers on which a selection or * selections are present.<p> * * This method is the most convenient way to iterate through selected * lines in a buffer. The line numbers in the array returned by this * method can be passed as a parameter to such methods as * {@link org.gjt.sp.jedit.Buffer#getLineText(int)}. * * @since jEdit 3.2pre1 */ public int[] getSelectedLines() { if(selection.size() == 0) return new int[] { caretLine }; Integer line; Set set = new TreeSet(); for(int i = 0; i < selection.size(); i++) { Selection s = (Selection)selection.elementAt(i); int endLine = (s.end == getLineStartOffset(s.endLine) ? s.endLine - 1 : s.endLine); for(int j = s.startLine; j <= endLine; j++) { line = new Integer(j); set.add(line); } } int[] returnValue = new int[set.size()]; int i = 0; Iterator iter = set.iterator(); while(iter.hasNext()) { line = (Integer)iter.next(); returnValue[i++] = line.intValue(); } return returnValue; } //}}} //{{{ showSelectLineRangeDialog() method /** * Displays the 'select line range' dialog box, and selects the * specified range of lines. * @since jEdit 2.7pre2 */ public void showSelectLineRangeDialog() { new SelectLineRange(view); } //}}} //}}} //{{{ Caret //{{{ addStructureMatcher() method /** * Adds a structure matcher. * @since jEdit 4.2pre3 */ public void addStructureMatcher(StructureMatcher matcher) { structureMatchers.add(matcher); } //}}} //{{{ removeStructureMatcher() method /** * Removes a structure matcher. * @since jEdit 4.2pre3 */ public void removeStructureMatcher(StructureMatcher matcher) { structureMatchers.remove(matcher); } //}}} //{{{ getStructureMatch() method /** * Returns the structure element (bracket, or XML tag, etc) matching the * one before the caret. * @since jEdit 4.2pre3 */ public StructureMatcher.Match getStructureMatch() { return match; } //}}} //{{{ blinkCaret() method /** * Blinks the caret. */ public final void blinkCaret() { if(caretBlinks) { blink = !blink; invalidateLine(caretLine); } else blink = true; } //}}} //{{{ centerCaret() method /** * Centers the caret on the screen. * @since jEdit 2.7pre2 */ public void centerCaret() { int offset = getScreenLineStartOffset(visibleLines / 2); if(offset == -1) getToolkit().beep(); else setCaretPosition(offset); } //}}} //{{{ setCaretPosition() method /** * Sets the caret position and deactivates the selection. * @param caret The caret position */ public void setCaretPosition(int newCaret) { invalidateSelectedLines(); selection.removeAllElements(); moveCaretPosition(newCaret,true); } //}}} //{{{ setCaretPosition() method /** * Sets the caret position and deactivates the selection. * @param caret The caret position * @param doElectricScroll Do electric scrolling? */ public void setCaretPosition(int newCaret, boolean doElectricScroll) { invalidateSelectedLines(); selection.removeAllElements(); moveCaretPosition(newCaret,doElectricScroll); } //}}} //{{{ moveCaretPosition() method /** * Sets the caret position without deactivating the selection. * @param caret The caret position */ public void moveCaretPosition(int newCaret) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -