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

int org::gjt::sp::jedit::textarea::TextArea::addExplicitFold ( int  caretStart,
int  caretEnd,
int  lineStart,
int  lineEnd 
) [inline, protected]

Add an explicit fold. You should call this method inside a compoundEdit in the buffer. You must also check if the buffer fold mode is explicit before calling this method.

Parameters:
caretStart the starting offset
caretEnd the end offset
lineStart the start line
lineEnd the end line
Since:
jEdit 4.3pre3

Definition at line 5830 of file TextArea.java.

References end(), org::gjt::sp::jedit::buffer::JEditBuffer::getContextSensitiveProperty(), org::gjt::sp::jedit::buffer::JEditBuffer::getLength(), org::gjt::sp::jedit::buffer::JEditBuffer::getLineLength(), org::gjt::sp::jedit::buffer::JEditBuffer::getLineStartOffset(), org::gjt::sp::jedit::buffer::JEditBuffer::getLineText(), org::gjt::sp::jedit::buffer::JEditBuffer::getSegment(), and org::gjt::sp::jedit::buffer::JEditBuffer::insert().

      {
            // need to "fix" the caret position so that we get the right rule.
            // taking the start offset one char ahead and the end offset one char
            // behing makes sure we get the right rule for the text being
            // wrapped (tricky around mode boundaries, e.g., php code embedded
            // in HTML code)
            int startCaret = caretStart < buffer.getLength() ? caretStart + 1 : caretStart;
            int endCaret = caretEnd > 0 ? caretEnd - 1 : caretEnd;

            String startLineComment = buffer.getContextSensitiveProperty(startCaret,"lineComment");
            String startCommentStart = buffer.getContextSensitiveProperty(startCaret,"commentStart");
            String startCommentEnd = buffer.getContextSensitiveProperty(startCaret,"commentEnd");
            String endLineComment = buffer.getContextSensitiveProperty(endCaret,"lineComment");
            String endCommentStart = buffer.getContextSensitiveProperty(endCaret,"commentStart");
            String endCommentEnd = buffer.getContextSensitiveProperty(endCaret,"commentEnd");

            String start;
            int caretBack = 1;
            if(startLineComment != null)
                  start = startLineComment + "{{{ ";
            else if(startCommentStart != null && startCommentEnd != null)
            {
                  start = startCommentStart + "{{{  " + startCommentEnd;
                  caretBack = 1 + startCommentStart.length();
            }
            else
                  start = "{{{ ";

            if (startLineComment != null)
            {
                  // add a new line if there's text after the comment
                  // we're inserting
                  if (buffer.getLineLength(lineStart) != caretStart)
                  {
                        start += '\n';
                  }
            }
            else
            {
                  // always insert a new line if there's no comment character.
                  start += "\n";
            }

            String end;
            if(endLineComment != null)
                  end = endLineComment + "}}}";
            else if(endCommentStart != null && endCommentEnd != null)
                  end = endCommentStart + "}}}" + endCommentEnd;
            else
                  end = "}}}";

            String line = buffer.getLineText(lineStart);
            String whitespace = line.substring(0,
                  StandardUtilities.getLeadingWhiteSpace(line));

            if (endLineComment != null)
            {
                  // if we're inserting a line comment into a non-empty
                  // line, we'll need to add a line break so we don't
                  // comment out existing code.
                  if (buffer.getLineLength(lineEnd) != caretEnd)
                  {
                        end += '\n';
                  }
            }
            else
            {
                  // always insert a new line if there's no comment character.
                  end += "\n";
            }

            if(caretEnd == buffer.getLineStartOffset(lineEnd))
                  buffer.insert(caretEnd,end);
            else
            {
                  CharSequence lineText = buffer.getSegment(caretEnd - 1, 1);
                  if (Character.isWhitespace(lineText.charAt(0)))
                        buffer.insert(caretEnd, end);
                  else
                        buffer.insert(caretEnd,' ' + end);
            }

            buffer.insert(caretStart,start + whitespace);

            return caretBack;
      } //}}}


Generated by  Doxygen 1.6.0   Back to index