Class ExpressionTextNavigation

java.lang.Object
org.cyclops.integrateddynamics.core.evaluate.expression.tree.ExpressionTextNavigation

public final class ExpressionTextNavigation extends Object
Words and brackets in the text of expressions, for moving through it and selecting parts of it. Words end where names, numbers, symbols and spaces meet, so item.size() has the words item, ., size, ( and ), where vanilla text fields only stop at spaces. Each bracket is a word of its own.
  • Method Details

    • getWordAt

      public static int[] getWordAt(String text, int index)
      Parameters:
      text - A text.
      index - The index of a character.
      Returns:
      The begin and end index of the word that contains the character, such as for a double-click.
    • getNextWordEnd

      public static int getNextWordEnd(String text, int cursor)
      Parameters:
      text - A text.
      cursor - The position of a cursor.
      Returns:
      The end of the next word after the cursor, skipping spaces.
    • getPreviousWordStart

      public static int getPreviousWordStart(String text, int cursor)
      Parameters:
      text - A text.
      cursor - The position of a cursor.
      Returns:
      The start of the previous word before the cursor, skipping spaces.
    • getBracketPartners

      public static int[] getBracketPartners(String text)
      Parameters:
      text - A text.
      Returns:
      For each character, the index of the bracket it is matched with, or -1 if it is no matched bracket. Brackets in strings are skipped.
    • getMatchingBrackets

      @Nullable public static int[] getMatchingBrackets(String text, int cursor)
      Parameters:
      text - A text.
      cursor - The position of a cursor.
      Returns:
      The indexes of the bracket next to the cursor and the bracket it is matched with, or null if there is none. The bracket before the cursor goes first, as it was usually just typed.
    • getLine

      public static int[] getLine(String text, int position)
      Parameters:
      text - A text.
      position - A position in it.
      Returns:
      The begin and end of the line at that position, between line breaks.
    • getKeyTarget

      @Nullable public static ExpressionTextNavigation.KeyTarget getKeyTarget(String text, int cursor, int lineBegin, int lineEnd, int key, boolean osx, boolean control, boolean alt)
      Where a key moves the cursor to, or deletes up to, for the keys where expressions differ from vanilla's text fields. Home and End move to the start or end of the line, not of the row it wraps on, as the text has no break there. Ctrl, or Option on macOS, moves and deletes by word. On macOS, Cmd moves and deletes to the start or end of the line, and Cmd with Up or Down to the start or end of the text, as in its own text fields.
      Parameters:
      text - A text.
      cursor - The position of the cursor.
      lineBegin - The begin of the line of the cursor, after the previous line break.
      lineEnd - The end of the line of the cursor, before the next line break.
      key - The key.
      osx - If this runs on macOS.
      control - If Ctrl is held, or Cmd on macOS, as for vanilla's edit shortcuts.
      alt - If Alt is held, which is Option on macOS.
      Returns:
      Where to, or null if the key works as in vanilla's text fields.