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

void org::gjt::sp::jedit::textarea::TextArea::formatParagraph (  )  throws TextAreaException [inline]

Formats the paragraph containing the caret.

Since:
jEdit 2.7pre2

Reimplemented in org::gjt::sp::jedit::textarea::JEditTextArea.

Definition at line 4138 of file TextArea.java.

References org::gjt::sp::jedit::buffer::JEditBuffer::beginCompoundEdit(), end(), org::gjt::sp::jedit::buffer::JEditBuffer::endCompoundEdit(), getCaretLine(), getCaretPosition(), org::gjt::sp::jedit::buffer::JEditBuffer::getLength(), getLineCount(), getLineEndOffset(), getLineStartOffset(), getSelectedText(), getSelection(), org::gjt::sp::jedit::buffer::JEditBuffer::getTabSize(), org::gjt::sp::jedit::buffer::JEditBuffer::getText(), org::gjt::sp::jedit::buffer::JEditBuffer::insert(), org::gjt::sp::jedit::buffer::JEditBuffer::isEditable(), lineContainsSpaceAndTabs(), moveCaretPosition(), org::gjt::sp::jedit::buffer::JEditBuffer::remove(), and setSelectedText().

      {
            if(!buffer.isEditable())
            {
                  getToolkit().beep();
                  return;
            }

            if(maxLineLen <= 0)
            {
                  throw new TextAreaException("format-maxlinelen");
            }

            Selection[] selection = getSelection();
            if(selection.length != 0)
            {
                  buffer.beginCompoundEdit();

                  for(int i = 0; i < selection.length; i++)
                  {
                        Selection s = selection[i];
                        setSelectedText(s,TextUtilities.format(
                              getSelectedText(s),maxLineLen,
                              buffer.getTabSize()));
                  }

                  buffer.endCompoundEdit();
            }
            else
            {
                  int lineNo = getCaretLine();

                  int start = 0, end = buffer.getLength();

                  for(int i = lineNo - 1; i >= 0; i--)
                  {
                        if (lineContainsSpaceAndTabs(i))
                        {
                              start = getLineEndOffset(i);
                              break;
                        }
                  }

                  for(int i = lineNo + 1; i < getLineCount(); i++)
                  {
                        if (lineContainsSpaceAndTabs(i))
                        {
                              end = getLineStartOffset(i) - 1;
                              break;
                        }
                  }

                  try
                  {
                        buffer.beginCompoundEdit();

                        String text = buffer.getText(start,end - start);
                        int offset = getCaretPosition() - start;
                        int noSpaceOffset = TextUtilities.indexIgnoringWhitespace(
                              text,offset);
                        buffer.remove(start,end - start);
                        text = TextUtilities.format(
                              text,maxLineLen,buffer.getTabSize());
                        buffer.insert(start,text);
                        int caretPos = start;
                        if (text.length() != 0)
                        {
                              caretPos += Math.min(text.length(),
                              TextUtilities.ignoringWhitespaceIndex(
                              text,noSpaceOffset));
                        }
                        moveCaretPosition(caretPos);
                  }
                  finally
                  {
                        buffer.endCompoundEdit();
                  }
            }
      } //}}}


Generated by  Doxygen 1.6.0   Back to index