PageRenderTime 73ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/macros/Editing/Greedy_Right.bsh

#
Unknown | 86 lines | 79 code | 7 blank | 0 comment | 0 complexity | 31b07e0d1729a88639545397fe5f6e9e 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
  1. /*
  2. * Greedy_Right.bsh - If a buffer is using soft tabs,
  3. * this macro will move the caret tabSize spaces to the right,
  4. * if all the characters between the caret and the next
  5. * tab stop are all spaces. In all other cases, the caret
  6. * is moved a single character to the right.
  7. *
  8. * Copyright (C) 2004 Ollie Rutherfurd <oliver@jedit.org>
  9. *
  10. * $Id: Greedy_Right.bsh 5230 2005-07-20 13:31:08Z orutherfurd $
  11. */
  12. /**
  13. * @param onlyFullTabs if true, the caret will only be moved
  14. * multiple spaces it would constitute
  15. * a 'complete' tab.
  16. */
  17. void greedyRight(View view, boolean onlyFullTabs)
  18. {
  19. JEditTextArea textArea = view.getTextArea();
  20. JEditBuffer buffer = textArea.getBuffer();
  21. int caret = textArea.getCaretPosition();
  22. int caretLine = textArea.getCaretLine();
  23. int lineStart = textArea.getLineStartOffset(caretLine);
  24. int lineEnd = textArea.getLineEndOffset(caretLine);
  25. if(textArea.getCaretPosition() == buffer.getLength())
  26. return;
  27. if(buffer.getBooleanProperty("noTabs") == true)
  28. {
  29. // if anything is selected, use standard
  30. if(textArea.getSelection().length != 0)
  31. {
  32. textArea.setCaretPosition(caret+1);
  33. }
  34. // if at the end of the line, go to the
  35. // start of the next line (+1 for \n)
  36. else if(caret+1 >= lineEnd)
  37. {
  38. textArea.setCaretPosition(caret+1);
  39. }
  40. else
  41. {
  42. int col = caret - lineStart;
  43. int tabSize = buffer.getIntegerProperty("tabSize",8);
  44. // unlikely, but just in case
  45. if(tabSize <= 0)
  46. {
  47. textArea.setCaretPosition(caret+11);
  48. }
  49. else
  50. {
  51. int toTabStop = (((col+tabSize)-1) % tabSize) + 1;
  52. String chunk = "";
  53. if((caret + toTabStop) <= buffer.getLength())
  54. chunk = buffer.getText(caret,toTabStop);
  55. int count = 0;
  56. for(int i=0; i < chunk.length(); i++)
  57. {
  58. if(' ' != chunk.charAt(i))
  59. {
  60. break;
  61. }
  62. count += 1;
  63. }
  64. // if onlyFullTabs must be only spaces to
  65. // the tabStop and must have tabSize number
  66. // of spaces to remove them all.
  67. if(onlyFullTabs == false || count == tabSize){
  68. textArea.setCaretPosition(caret+count);
  69. }
  70. else{
  71. textArea.setCaretPosition(caret+1);
  72. }
  73. }
  74. }
  75. }
  76. else
  77. textArea.setCaretPosition(caret+1);
  78. }
  79. greedyRight(view,true);