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

📄 hypertyperaction.java

📁 java写的多功能文件编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        int end = lineElement.getEndOffset() - 1;        int length = end - start;        int startPos = textArea.getCaretPosition();        if (startPos == end)        {            if (startPos == start)            {                textArea.endCompoundEdit();                return;            }            else            {                startPos--;            }        }        String _line = textArea.getText(start, length);        int linePos = startPos - start;        int wordStart = -1;        int wordEnd = -1;        if (delimiters.indexOf(_line.charAt(linePos)) != -1)        {            if (linePos > 0)            {                if (delimiters.indexOf(_line.charAt(linePos - 1)) != -1)                {                    textArea.endCompoundEdit();                    return;                }                else                {                    wordEnd = linePos;                }            }            for (int i = linePos - 1; i >= 0; i--)            {                if (delimiters.indexOf(_line.charAt(i)) != -1)                {                    wordStart = i + 1;                    break;                }            }        }        else        {            // case caret is placed on a word            for (int i = linePos; i < length; i++)            {                if (delimiters.indexOf(_line.charAt(i)) != -1)                {                    wordEnd = i;                    break;                }            }            for (int i = linePos; i >= 0; i--)            {                if (delimiters.indexOf(_line.charAt(i)) != -1)                {                    wordStart = i + 1;                    break;                }            }        }        if (wordStart == -1)        {            wordStart = 0;        }        if (wordEnd == -1)        {            wordEnd = length;        }        //        // Expand the text        //        String expanded = this.htMap.getExpandedText( _line.substring( wordStart, wordEnd ) );        int insertPos = 0;        if (expanded != null)        {            textArea.beginProtectedCompoundEdit();            try            {						    if (wordEnd != _line.length() && _line.charAt(wordEnd) == SPACE)								{//									could just trim but we only want to treat spaces, not other whitespace chars.									StringBuffer workBuf = new StringBuffer(expanded);									int wbLen;									for (wbLen = workBuf.length();									 workBuf.charAt(wbLen - 1) == SPACE; wbLen--);									workBuf.setLength(wbLen);									expanded = workBuf.toString();								}//end if expanded ends with a space and next char is also a space                doc.remove(wordStart + start, wordEnd - wordStart);                // avoid computing this operation all the other times                wordStart += start;                StringBuffer _buf = new StringBuffer(expanded.length());                // 0 = not set                // 1 = set                // 2 = set & indent once                int caretState = 0;                boolean onFirstLine = true, wasFirstLine = false;                int lastBreak = -1;                // by default, the caret position is at the end of the                // expanded text.                int caret = expanded.length();                char c;out:            for (int i = 0 ; i < expanded.length(); i++)                {                    switch (c = expanded.charAt(i))                    {                        case '|':                            if (i < expanded.length() - 1 &&                                expanded.charAt(i + 1) == '|')                            {                                i++;                                _buf.append('|');                            }                            else                            {                                // Only set the caret the first time                                // This is a disputable check.                                if (caretState == 0)                                {                                    caret = insertPos + _buf.length();                                    caretState = 1;                                    // don't do indent on next line!                                    if (onFirstLine)                                    {                                        wasFirstLine = true;                                    }                                }                            }                          break;                        case '\n':                            // put the proper tabbing after the new-line                            // but only if we are not on the first line                            if (textArea.getEnterIndent() && !onFirstLine)                            {                                // In order to indent correctly,                                // we need to put the so-far text                                // into the document.                                doc.insertString( wordStart +                                    insertPos, _buf.toString(), null );                                // So increment the incremental inserting                                // position counter                                insertPos += _buf.length();                                // and start the buffer over clean// this is a JDK1.2 call - so 86 it.//                                _buf.delete( 0, _buf.length() );// and instead use a JDK1.1 call; here we need to create a new buffer                                _buf = new StringBuffer( expanded.length() -                                    _buf.length() );                                // and indent                                int tempLen = doc.getLength();                                Indent.indent(textArea, textArea.getCaretLine(), true, false);                                // Now we need to increment the                                // incremental inserting position counter                                // by the indention amount.                                int indentLen = doc.getLength() - tempLen;                                // Adjust the caret position to                                // reflect the insertion, if it has just been                                // set.                                if (caretState == 1)                                {                                    if (!wasFirstLine)                                    {                                        caret += indentLen;                                    }                                    caretState = 2;                                }                                insertPos += indentLen;                                wasFirstLine = false;                            }                            _buf.append('\n');                            onFirstLine = false;                            lastBreak = i;                            break;                        default:                            _buf.append(c);                    }                }                doc.insertString(wordStart + insertPos,                    _buf.toString(), null);                // perform a final insert, if we're not on the first line                if (!onFirstLine)                {                    int tempLen = doc.getLength();                    Indent.indent(textArea, textArea.getCaretLine(), true, false);                    // possibly adjust the caret position                    if (lastBreak < caret && caretState <= 1)                    {                        caret += doc.getLength() - tempLen;                    }                }                // set the caret position correctly,                // without going past the end of the file.                int caretPos = wordStart + caret;                int tempLen = doc.getLength();                if (caretPos > tempLen)                {                    caretPos = tempLen;                }                textArea.setCaretPosition( caretPos );            }            catch (BadLocationException ble)            {                // do nothing            }            textArea.endProtectedCompoundEdit();        }        textArea.endCompoundEdit();    } // end HyperTyper action!}

⌨️ 快捷键说明

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