products/sources/formale sprachen/Java/openjdk-20-36_src/test/jdk/java/io/InputStream image not shown  

Quellcode-Bibliothek

© Kompilation durch diese Firma

[Weder Korrektheit noch Funktionsfähigkeit der Software werden zugesichert.]

Datei: Go_to_Column.bsh   Sprache: C

Columbo aufrufen.bsh zum Wurzelverzeichnis wechselnCS {CS[86] Ada[99] Abap[128]}Datei anzeigen

/*
 * Greedy_Right.bsh - If a buffer is using soft tabs,
 * this macro will move the caret tabSize spaces to the right,
 * if all the characters between the caret and the next
 * tab stop are all spaces.  In all other cases, the caret
 * is moved a single character to the right.
 *
 * Copyright (C) 2004 Ollie Rutherfurd <[email protected]>
 *
 * $Id: Greedy_Right.bsh 5230 2005-07-20 13:31:08Z orutherfurd $
 */


/**
 * @param onlyFullTabs if true, the caret will only be moved
 *                     multiple spaces it would constitute
 *                     a 'complete' tab.
 */

void greedyRight(View view, boolean onlyFullTabs)
{
 JEditTextArea textArea = view.getTextArea();
 JEditBuffer buffer = textArea.getBuffer();
 int caret = textArea.getCaretPosition();
 int caretLine = textArea.getCaretLine();
 int lineStart = textArea.getLineStartOffset(caretLine);
 int lineEnd = textArea.getLineEndOffset(caretLine);

 if(textArea.getCaretPosition() == buffer.getLength())
  return;

 if(buffer.getBooleanProperty("noTabs") == true)
 {
  // if anything is selected, use standard 
  if(textArea.getSelection().length != 0)
  {
   textArea.setCaretPosition(caret+1);
  }
  // if at the end of the line, go to the 
  // start of the next line (+1 for \n)
  else if(caret+1 >= lineEnd)
  {
   textArea.setCaretPosition(caret+1);
  }
  else
  {
   int col = caret - lineStart;
   int tabSize = buffer.getIntegerProperty("tabSize",8);

   // unlikely, but just in case
   if(tabSize <= 0)
   {
    textArea.setCaretPosition(caret+11);
   }
   else
   {
    int toTabStop = (((col+tabSize)-1) % tabSize) + 1;
    String chunk = "";
    if((caret + toTabStop) <= buffer.getLength())
     chunk = buffer.getText(caret,toTabStop);
    int count = 0;
    for(int i=0; i < chunk.length(); i++)
    {
     if(' ' != chunk.charAt(i))
     {
      break;
     }
     count += 1;
    }

    // if onlyFullTabs must be only spaces to
    // the tabStop and must have tabSize number 
    // of spaces to remove them all.
    if(onlyFullTabs == false || count == tabSize){
     textArea.setCaretPosition(caret+count);
    }
    else{
     textArea.setCaretPosition(caret+1);
    }
   }
  }
 }
 else
  textArea.setCaretPosition(caret+1);
}

greedyRight(view,true);


[ Original von:0.477Diese Quellcodebibliothek enthält Beispiele in vielen Programmiersprachen. Man kann per Verzeichnistruktur darin navigieren. Der Code wird farblich markiert angezeigt.  ]