/** * Get the starting position of the row while providing relative count of * row how the given position should be shifted. This is the most efficient * way how to move by lines in the document based on some position. There is * no similair getRowEnd() method that would have shifting parameter. * * @param doc * document to operate on * @param offset * position in document where to start searching * @param lineShift * shift the given offset forward/back relatively by some amount * of lines * @return position of the start of the row or -1 for invalid position */ public static int getRowStart(BaseDocument doc, int offset, int lineShift) throws BadLocationException { if (lineShift != 0) { return doc.op.getBOLRelLine(offset, lineShift); } else { // no shift return doc.op.getBOL(offset); } }
BaseDocument doc = (BaseDocument) getDocument(); int visCol = doc.op.getVisColFromPos(pos); pos = doc.op.getOffsetFromVisCol(visCol, doc.op.getBOLRelLine(pos, -1)); } catch (BadLocationException e) { BaseDocument doc = (BaseDocument) getDocument(); int visCol = doc.op.getVisColFromPos(pos); pos = doc.op.getOffsetFromVisCol(visCol, doc.op.getBOLRelLine(pos, 1)); } catch (BadLocationException e) {