return; DefaultPositionUpdater updater= new DefaultPositionUpdater(getCategory()); Position caretPosition= null; try { if (updateCaret()) { document.addPositionCategory(getCategory()); document.addPositionUpdater(updater); caretPosition= new Position(caretOffset); document.addPosition(getCategory(), caretPosition); if (updateCaret()) { document.removePositionUpdater(updater); try { document.removePositionCategory(getCategory()); } catch (BadPositionCategoryException e) { Assert.isTrue(false);
/** * Adds an additional replace command. The added replace command must not overlap * with existing ones. If the document command owner is not <code>null</code>, it will not * get document change notifications for the particular command. * * @param commandOffset the offset of the region to replace * @param commandLength the length of the region to replace * @param commandText the text to replace with, may be <code>null</code> * @param commandOwner the command owner, may be <code>null</code> * @throws BadLocationException if the added command intersects with an existing one * @since 2.1 */ public void addCommand(int commandOffset, int commandLength, String commandText, IDocumentListener commandOwner) throws BadLocationException { final Command command= new Command(commandOffset, commandLength, commandText, commandOwner); if (intersects(command)) throw new BadLocationException(); final int index= Collections.binarySearch(fCommands, command); // a command with exactly the same ranges exists already if (index >= 0) throw new BadLocationException(); // binary search result is defined as (-(insertionIndex) - 1) final int insertionIndex= -(index + 1); // overlaps to the right? if (insertionIndex != fCommands.size() && intersects(fCommands.get(insertionIndex), command)) throw new BadLocationException(); // overlaps to the left? if (insertionIndex != 0 && intersects(fCommands.get(insertionIndex - 1), command)) throw new BadLocationException(); fCommands.add(insertionIndex, command); }
fDocumentCommand.setEvent(e, modelRange); customizeDocumentCommand(fDocumentCommand); if (!fDocumentCommand.fillEvent(e, modelRange)) { boolean compoundChange= fDocumentCommand.getCommandCount() > 1; try { fUndoManager.beginCompoundChange(); fDocumentCommand.execute(getDocument());
fDocumentCommand.setEvent(e, modelRange); customizeDocumentCommand(fDocumentCommand); if (!fDocumentCommand.fillEvent(e, modelRange)) { boolean compoundChange= fDocumentCommand.getCommandCount() > 1; try { fUndoManager.beginCompoundChange(); fDocumentCommand.execute(getDocument());
return; DefaultPositionUpdater updater= new DefaultPositionUpdater(getCategory()); Position caretPosition= null; try { if (updateCaret()) { document.addPositionCategory(getCategory()); document.addPositionUpdater(updater); caretPosition= new Position(caretOffset); document.addPosition(getCategory(), caretPosition); if (updateCaret()) { document.removePositionUpdater(updater); try { document.removePositionCategory(getCategory()); } catch (BadPositionCategoryException e) { Assert.isTrue(false);
/** * Adds an additional replace command. The added replace command must not overlap * with existing ones. If the document command owner is not <code>null</code>, it will not * get document change notifications for the particular command. * * @param commandOffset the offset of the region to replace * @param commandLength the length of the region to replace * @param commandText the text to replace with, may be <code>null</code> * @param commandOwner the command owner, may be <code>null</code> * @throws BadLocationException if the added command intersects with an existing one * @since 2.1 */ public void addCommand(int commandOffset, int commandLength, String commandText, IDocumentListener commandOwner) throws BadLocationException { final Command command= new Command(commandOffset, commandLength, commandText, commandOwner); if (intersects(command)) throw new BadLocationException(); final int index= Collections.binarySearch(fCommands, command); // a command with exactly the same ranges exists already if (index >= 0) throw new BadLocationException(); // binary search result is defined as (-(insertionIndex) - 1) final int insertionIndex= -(index + 1); // overlaps to the right? if (insertionIndex != fCommands.size() && intersects(fCommands.get(insertionIndex), command)) throw new BadLocationException(); // overlaps to the left? if (insertionIndex != 0 && intersects(fCommands.get(insertionIndex - 1), command)) throw new BadLocationException(); fCommands.add(insertionIndex, command); }