/jEdit/tags/jedit-4-2-pre14/macros/Editing/Greedy_Right.bsh
Unknown | 87 lines | 80 code | 7 blank | 0 comment | 0 complexity | 028a2d3aaef7374a7de2d1526ef51003 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * 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 <oliver@jedit.org>
- *
- * $Id: Greedy_Right.bsh 5032 2004-05-06 19:53:37Z 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();
- Buffer 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;
- int count = 1;
- for(int i=1; i < toTabStop; i++)
- {
- int pos = caret+i+1;
- if(pos > buffer.getLength())
- break;
- if(!" ".equals(buffer.getText(caret+i,1)))
- 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);
- }
- if(buffer.isReadOnly())
- getToolkit().beep();
- else
- greedyRight(view,true);