Logo Search packages:      
Sourcecode: jedit version File versions  Download package

void org::gjt::sp::jedit::textarea::TextArea::goToEndOfCode ( boolean  select  )  [inline]

Moves the caret to the end of the code present on the current line, before the comments and whitespace.

Parameters:
select true if you want to extend selection
Since:
jEdit 4.3pre18

Definition at line 3052 of file TextArea.java.

References extendSelection(), getCaretLine(), getLineLength(), getLineStartOffset(), getLineText(), org::gjt::sp::jedit::syntax::DefaultTokenHandler::getTokens(), org::gjt::sp::jedit::syntax::Token::id, org::gjt::sp::jedit::syntax::Token::length, org::gjt::sp::jedit::buffer::JEditBuffer::markTokens(), moveCaretPosition(), multi, org::gjt::sp::jedit::syntax::Token::next, org::gjt::sp::jedit::syntax::Token::offset, and selectNone().

Referenced by smartEnd().

      {
            int line = getCaretLine();

            // @todo - Should tokenHandler be an TextArea instance variable?
            DefaultTokenHandler tokenHandler = new DefaultTokenHandler();
            buffer.markTokens(line,tokenHandler);
            Token token = tokenHandler.getTokens();

            char[] txt = getLineText(line).toCharArray();

            // replace comments with whitespace to find endOfCode:
            while(true)
            {
                  if( token.id == Token.COMMENT1 ||
                        token.id == Token.COMMENT2 ||
                        token.id == Token.COMMENT3 ||
                        token.id == Token.COMMENT4)
                  {
                        for(int i=token.offset; i<token.offset+token.length; i++)
                        {
                              txt[i] = ' ';
                        }
                  }

                  if(token.next == null)
                        break;
                  token = token.next;
            }

            int newCaret = getLineLength(line) - StandardUtilities.getTrailingWhiteSpace( new String(txt) );
            newCaret += getLineStartOffset(line);

            if(select)
                  extendSelection(caret,newCaret);
            else if(!multi)
                  selectNone();
            moveCaretPosition(newCaret);
      } //}}}


Generated by  Doxygen 1.6.0   Back to index