示例#1
0
 @Override
 public void enterMode(final ModeSwitchHint... hints) throws CommandExecutionException {
   boolean fixSelection = false;
   boolean keepSelection = false;
   boolean recallSelection = false;
   ExecuteCommandHint onEnterCommand = null;
   for (final ModeSwitchHint hint : hints) {
     if (hint == FIX_SELECTION_HINT) {
       keepSelection = true;
       fixSelection = true;
     }
     if (hint == KEEP_SELECTION_HINT) {
       keepSelection = true;
     }
     if (hint == RECALL_SELECTION_HINT) {
       recallSelection = true;
     }
     if (hint instanceof ExecuteCommandHint) {
       onEnterCommand = (ExecuteCommandHint) hint;
     }
   }
   if (recallSelection) {
     Selection previousSel = editorAdaptor.getLastActiveSelection();
     CursorService cursorService = editorAdaptor.getCursorService();
     Position from = cursorService.getMark(CursorService.INTERNAL_LAST_SELECT_FROM_MARK);
     Position to = cursorService.getMark(CursorService.INTERNAL_LAST_SELECT_TO_MARK);
     if (previousSel == null) {
       VrapperLog.info("Previous selection was null, selection not recalled.");
     } else {
       Selection updatedSel = updateSelection(editorAdaptor, previousSel, from, to);
       // Makes sure to set the sticky column.
       editorAdaptor.setPosition(updatedSel.getTo(), StickyColumnPolicy.ON_CHANGE);
       editorAdaptor.setSelection(updatedSel);
     }
   } else if (!keepSelection) {
     editorAdaptor.setSelection(null);
   }
   Selection currentSelection = editorAdaptor.getSelection();
   if (fixSelection && currentSelection != null) {
     editorAdaptor.setSelection(fixSelection(currentSelection));
   }
   super.enterMode(hints);
   if (onEnterCommand != null) {
     try {
       super.executeCommand(onEnterCommand.getCommand());
     } catch (final CommandExecutionException e) {
       editorAdaptor.getUserInterfaceService().setErrorMessage(e.getMessage());
     }
   }
   fixCaret();
 }
示例#2
0
 private Selection updateSelection(
     EditorAdaptor editorAdaptor, Selection previousSel, Position from, Position to) {
   // Can happen if the user deleted a piece of text containing the mark or indented.
   // Also frequently happens during tests, as the stubbed mark service doesn't keep marks.
   if (from == null && to == null) {
     VrapperLog.info("Previous selection marks are null, selection might be wrong.");
   } else if (from == null) {
     VrapperLog.info("Previous selection 'from' mark is null, selection might be wrong.");
   } else if (to == null) {
     VrapperLog.info("Previous selection 'to' mark is null, selection might be wrong.");
   }
   if (from == null) {
     from = previousSel.getFrom();
   }
   if (to == null) {
     to = previousSel.getTo();
   }
   return previousSel.reset(editorAdaptor, from, to);
 }