Beispiel #1
0
    /** Is called while characters is removed. */
    @Override
    public void remove(final int offs, final int len) throws BadLocationException {
      mPosLock.lock();
      if (offs >= commandOffset) {

        for (final String cheat : CHEATS_MAP.keySet()) {
          final int cheatPos = CHEATS_MAP.get(cheat);
          if (cheatPos > 0) {
            CHEATS_MAP.put(cheat, cheatPos - 1);
          }
        }
        if (editEnabled) {
          super.remove(offs, len);
        }
      }
      mPosLock.unlock();
    }
Beispiel #2
0
 /** Is called while a string is inserted. It checks if a cheat code is in the string. */
 @Override
 public void insertString(int offs, final String s, final AttributeSet a)
     throws BadLocationException {
   mPosLock.lock();
   if (offs < commandOffset) {
     terminalArea.setCaretPosition(commandOffset);
     offs = commandOffset;
   }
   if (userCommand) {
     if (editEnabled) {
       if (s.charAt(s.length() - 1) == '\n') {
         final int end = terminalArea.getDocument().getLength();
         super.insertString(end, "\n", commandColor);
         final String command = (getText(commandOffset, end - commandOffset) + s).trim();
         prevLine = end + 1;
         pos = end;
         maxPos = end;
         execCommand(command);
       } else {
         super.insertString(offs, s, commandColor);
       }
     }
     for (final String cheat : CHEATS_MAP.keySet()) {
       int cheatPos = CHEATS_MAP.get(cheat);
       if (s.equals(cheat.substring(cheatPos, cheatPos + 1))) {
         cheatPos++;
         CHEATS_MAP.put(cheat, cheatPos);
         if (cheatPos == cheat.length()) {
           for (final String ch : CHEATS_MAP.keySet()) {
             CHEATS_MAP.put(ch, 0);
           }
           startCheat(cheat);
         }
       } else {
         CHEATS_MAP.put(cheat, 0);
       }
     }
   } else {
     super.insertString(offs, s, a);
   }
   mPosLock.unlock();
 }