Skip to content

Commit

Permalink
TextDocument to expose an API for getting a document line number by o…
Browse files Browse the repository at this point in the history
…ffset #1519
  • Loading branch information
vrubezhny authored and angelozerr committed May 18, 2023
1 parent 92210e6 commit 7c2c591
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2018 Angelo ZERR.
* Copyright (c) 2018, 2023 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -84,6 +84,18 @@ public int lineOffsetAt(int position) throws BadLocationException {
return line.offset;
}

/**
* Returns the line number the character at the given offset belongs to.
*
* @param position the offset whose line number to be determined
* @return the number of the line the offset is on
* @exception BadLocationException if the offset is invalid in this tracker
*/
public int lineAt(int position) throws BadLocationException {
ILineTracker lineTracker = getLineTracker();
return lineTracker.getLineNumberOfOffset(position);
}

public String lineDelimiter(int lineNumber) throws BadLocationException {
ILineTracker lineTracker = getLineTracker();
String lineDelimiter = lineTracker.getLineDelimiter(lineNumber);
Expand Down

0 comments on commit 7c2c591

Please sign in to comment.