⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jedittextarea.java

📁 Linux下面最好用的程序、文本编辑工具之一。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			{				startLine = i;			}			if((info.physicalLine >= line && info.lastSubregion)				|| info.physicalLine == -1)			{				endLine = i;				break;			}		}		if(chunkCache.needFullRepaint() || endLine == -1)			endLine = visibleLines;		//if(startLine != endLine)		//	System.err.println(startLine + ":" + endLine);		invalidateScreenLineRange(startLine,endLine);	} //}}}	//{{{ invalidateLineRange() method	/**	 * Marks a range of physical lines as needing a repaint.	 * @param start The first line to invalidate	 * @param end The last line to invalidate	 */	public void invalidateLineRange(int start, int end)	{		if(!isShowing() || !buffer.isLoaded())			return;		if(end < start)		{			int tmp = end;			end = start;			start = tmp;		}		if(end < getFirstPhysicalLine() || start > getLastPhysicalLine())			return;		int startScreenLine = -1;		int endScreenLine = -1;		for(int i = 0; i < visibleLines; i++)		{			ChunkCache.LineInfo info = chunkCache.getLineInfo(i);			if((info.physicalLine >= start || info.physicalLine == -1)				&& startScreenLine == -1)			{				startScreenLine = i;			}			if((info.physicalLine >= end && info.lastSubregion)				|| info.physicalLine == -1)			{				endScreenLine = i;				break;			}		}		if(startScreenLine == -1)			startScreenLine = 0;		if(chunkCache.needFullRepaint() || endScreenLine == -1)			endScreenLine = visibleLines;		invalidateScreenLineRange(startScreenLine,endScreenLine);	} //}}}	//{{{ invalidateSelectedLines() method	/**	 * Repaints the lines containing the selection.	 */	public void invalidateSelectedLines()	{		// to hide line highlight if selections are being added later on		invalidateLine(caretLine);		for(int i = 0; i < selection.size(); i++)		{			Selection s = (Selection)selection.elementAt(i);			invalidateLineRange(s.startLine,s.endLine);		}	} //}}}	//}}}	//{{{ Convenience methods	//{{{ getBufferLength() method	/**	 * Returns the length of the buffer.	 */	public final int getBufferLength()	{		return buffer.getLength();	} //}}}	//{{{ getLineCount() method	/**	 * Returns the number of physical lines in the buffer.	 */	public final int getLineCount()	{		return buffer.getLineCount();	} //}}}	//{{{ getLineOfOffset() method	/**	 * Returns the line containing the specified offset.	 * @param offset The offset	 */	public final int getLineOfOffset(int offset)	{		return buffer.getLineOfOffset(offset);	} //}}}	//{{{ getLineStartOffset() method	/**	 * Returns the start offset of the specified line.	 * @param line The line	 * @return The start offset of the specified line, or -1 if the line is	 * invalid	 */	public int getLineStartOffset(int line)	{		return buffer.getLineStartOffset(line);	} //}}}	//{{{ getLineEndOffset() method	/**	 * Returns the end offset of the specified line.	 * @param line The line	 * @return The end offset of the specified line, or -1 if the line is	 * invalid.	 */	public int getLineEndOffset(int line)	{		return buffer.getLineEndOffset(line);	} //}}}	//{{{ getLineLength() method	/**	 * Returns the length of the specified line.	 * @param line The line	 */	public int getLineLength(int line)	{		return buffer.getLineLength(line);	} //}}}	//{{{ getText() method	/**	 * Returns the specified substring of the buffer.	 * @param start The start offset	 * @param len The length of the substring	 * @return The substring	 */	public final String getText(int start, int len)	{		return buffer.getText(start,len);	} //}}}	//{{{ getText() method	/**	 * Copies the specified substring of the buffer into a segment.	 * @param start The start offset	 * @param len The length of the substring	 * @param segment The segment	 */	public final void getText(int start, int len, Segment segment)	{		buffer.getText(start,len,segment);	} //}}}	//{{{ getLineText() method	/**	 * Returns the text on the specified line.	 * @param lineIndex The line	 * @return The text, or null if the line is invalid	 */	public final String getLineText(int lineIndex)	{		return buffer.getLineText(lineIndex);	} //}}}	//{{{ getLineText() method	/**	 * Copies the text on the specified line into a segment. If the line	 * is invalid, the segment will contain a null string.	 * @param lineIndex The line	 */	public final void getLineText(int lineIndex, Segment segment)	{		buffer.getLineText(lineIndex,segment);	} //}}}	//{{{ getText() method	/**	 * Returns the entire text of this text area.	 */	public String getText()	{		return buffer.getText(0,buffer.getLength());	} //}}}	//{{{ setText() method	/**	 * Sets the entire text of this text area.	 */	public void setText(String text)	{		try		{			buffer.beginCompoundEdit();			buffer.remove(0,buffer.getLength());			buffer.insert(0,text);		}		finally		{			buffer.endCompoundEdit();		}	} //}}}	//}}}	//{{{ Selection	//{{{ selectAll() method	/**	 * Selects all text in the buffer.	 */	public final void selectAll()	{		setSelection(new Selection.Range(0,buffer.getLength()));		moveCaretPosition(buffer.getLength(),true);	} //}}}	//{{{ selectLine() method	/**	 * Selects the current line.	 * @since jEdit 2.7pre2	 */	public void selectLine()	{		int caretLine = getCaretLine();		int start = getLineStartOffset(caretLine);		int end = getLineEndOffset(caretLine) - 1;		Selection s = new Selection.Range(start,end);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(end);	} //}}}	//{{{ selectParagraph() method	/**	 * Selects the paragraph at the caret position.	 * @since jEdit 2.7pre2	 */	public void selectParagraph()	{		int caretLine = getCaretLine();		if(getLineLength(caretLine) == 0)		{			getToolkit().beep();			return;		}		int start = caretLine;		int end = caretLine;		while(start >= 0)		{			if(getLineLength(start) == 0)				break;			else				start--;		}		while(end < getLineCount())		{			if(getLineLength(end) == 0)				break;			else				end++;		}		int selectionStart = getLineStartOffset(start + 1);		int selectionEnd = getLineEndOffset(end - 1) - 1;		Selection s = new Selection.Range(selectionStart,selectionEnd);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(selectionEnd);	} //}}}	//{{{ selectWord() method			/**	 * Selects the word at the caret position.	 * @since jEdit 2.7pre2	 */	public void selectWord()	{		int line = getCaretLine();		int lineStart = getLineStartOffset(line);		int offset = getCaretPosition() - lineStart;		if(getLineLength(line) == 0)			return;		String lineText = getLineText(line);		String noWordSep = buffer.getStringProperty("noWordSep");		if(offset == getLineLength(line))			offset--;		int wordStart = TextUtilities.findWordStart(lineText,offset,noWordSep);		int wordEnd = TextUtilities.findWordEnd(lineText,offset+1,noWordSep);		Selection s = new Selection.Range(lineStart + wordStart,			lineStart + wordEnd);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(lineStart + wordEnd);	} //}}}	//{{{ selectToMatchingBracket() method	/**	 * Selects from the bracket at the specified position to the 	 * corresponding bracket.	 * @since jEdit 4.2pre1	 */	public Selection selectToMatchingBracket(int position,		boolean quickCopy)	{		int positionLine = buffer.getLineOfOffset(position);		int lineOffset = position - buffer.getLineStartOffset(positionLine);		if(getLineLength(positionLine) != 0)		{			int bracket = TextUtilities.findMatchingBracket(buffer,				positionLine,Math.max(0,lineOffset - 1));			if(bracket != -1)			{				Selection s;				if(bracket < position)				{					if(!quickCopy)						moveCaretPosition(position,false);					s = new Selection.Range(bracket,position);				}				else				{					if(!quickCopy)						moveCaretPosition(bracket + 1,false);					s = new Selection.Range(position - 1,bracket + 1);				}				if(!multi && !quickCopy)					selectNone();				addToSelection(s);				return s;			}		}		return null;	} //}}}	//{{{ selectToMatchingBracket() method	/**	 * Selects from the bracket at the caret position to the corresponding	 * bracket.	 * @since jEdit 4.0pre2	 */	public void selectToMatchingBracket()	{		selectToMatchingBracket(caret,false);	} //}}}	//{{{ selectBlock() method	/**	 * Selects the code block surrounding the caret.	 * @since jEdit 2.7pre2	 */	public void selectBlock()	{		String openBrackets = "([{";		String closeBrackets = ")]}";		Selection s = getSelectionAtOffset(caret);		int start, end;		if(s == null)			start = end = caret;		else		{			start = s.start;			end = s.end;		}		String text = getText(0,buffer.getLength());		// Scan backwards, trying to find a bracket		int count = 1;		char openBracket = '\0';		char closeBracket = '\0';		// We can't do the backward scan if start == 0		if(start == 0)		{			getToolkit().beep();			return;		}backward_scan:	while(--start > 0)		{			char c = text.charAt(start);			int index = openBrackets.indexOf(c);			if(index != -1)			{				if(--count == 0)				{					openBracket = c;					closeBracket = closeBrackets.charAt(index);					break backward_scan;				}			}			else if(closeBrackets.indexOf(c) != -1)				count++;		}		// Reset count		count = 1;		// Scan forward, matching that bracket		if(openBracket == '\0')		{			getToolkit().beep();			return;		}		else		{forward_scan:		do			{				char c = text.charAt(end);				if(c == closeBracket)				{					if(--count == 0)					{						end++;						break forward_scan;					}				}				else if(c == openBracket)					count++;			}			while(++end < buffer.getLength());		}		s = new Selection.Range(start,end);		if(multi)			addToSelection(s);		else			setSelection(s);		moveCaretPosition(end);	} //}}}	//{{{ lineInStructureScope() method	/**	 * Returns if the specified line is contained in the currently	 * matched structure's scope.	 * @since jEdit 4.2pre3	 */	public boolean lineInStructureScope(int line)	{		if(match == null)			return false;		if(match.startLine < caretLine)			return (line >= match.startLine && line <= caretLine);		else			return (line <= match.endLine && line >= caretLine);	} //}}}	//{{{ invertSelection() method	/**	 * Inverts the selection.	 * @since jEdit 4.0pre1	 */	public final void invertSelection()	{		Selection[] newSelection = new Selection[selection.size() + 1];		int lastOffset = 0;		for(int i = 0; i < selection.size(); i++)		{			Selection s = (Selection)selection.elementAt(i);			newSelection[i] = new Selection.Range(lastOffset,				s.getStart());			lastOffset = s.getEnd();		}		newSelection[selection.size()] = new Selection.Range(			lastOffset,buffer.getLength());		setSelection(newSelection);	} //}}}	//{{{ getSelectionCount() method	/**	 * Returns the number of selections. This can be used to test	 * for the existence of selections.	 * @since jEdit 3.2pre2	 */	public int getSelectionCount()	{		return selection.size();	} //}}}	//{{{ getSelection() method	/**	 * Returns the current selection.	 * @since jEdit 3.2pre1	 */	public Selection[] getSelection()	{		Selection[] sel = new Selection[selection.size()];		selection.copyInto(sel);		return sel;	} //}}}	//{{{ selectNone() method	/**	 * 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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -