begin = editor.createPositionRef(p1, begin.getPositionBias()); end = editor.createPositionRef(p1 + len, end.getPositionBias());
doc.remove(p1 + len, p2 - p1); if (begin.getOffset() != p1) begin = editor.createPositionRef(p1, begin.getPositionBias()); if (end.getOffset() - p1 != len) end = editor.createPositionRef(p1 + len, end.getPositionBias());
doc.remove(p1 + len, p2 - p1); if (begin.getOffset() != p1) begin = editor.createPositionRef(p1, begin.getPositionBias()); if (end.getOffset() - p1 != len) end = editor.createPositionRef(p1 + len, end.getPositionBias());
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString(p1, text, null); int p2 = (p1 + doc.getLength()) - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString (p1, text, null); int p2 = p1 + doc.getLength() - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString (p1, text, null); int p2 = p1 + doc.getLength() - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };