Open VladimirMakaev opened 1 month ago
Letter lengths have many meanings and are often confusing.
In the case of (1), it is easy to provide, because it is managed by RowIndex
.
However, this is probably not what is required.
So we added a method to get the range string, not the length(v0.5.3).
/**
* Gets the text at the specified range.
* @param startRow the start row
* @param startCol the start col
* @param endRow the end row
* @param endCol the end col
* @return the text of the specified range
*/
default String getText(int startRow, int startCol, int endRow, int endCol) {
return getText(new Pos(startRow, startCol), new Pos(endRow, endCol));
}
/**
* Gets the text list at the specified range.
* @param start the start pos
* @param end the end pos
* @return the text of the specified range
*/
String getText(Pos start, Pos end);
Perhaps that is in line with your original intent!
getText(1, 0, 2, 5).length();
@naotsugu Thanks for that, but what I really need is ability to apply TextEdit to a given document. So essentially:
replace(Pos start, Pos end, String newText)
or alternatively
delete(Pos start, Pos end)
insert(Pos start, String newText) // this already exists
Also having getRowLength(int row)
would help in other cases
The following methods have been added for editing selections.
default Pos replace(int startRow, int startCol, int endRow, int endCol, String text) {
return replace(new Pos(startRow, startCol), new Pos(endRow, endCol), text);
}
default Pos replace(Pos start, Pos end, String text) {
return replace(
start.row(), start.col(),
getText(start, end).length() * (int) Math.signum(end.compareTo(start)),
text);
}
@naotsugu I did a few tests and I think there is still a bug in how rows()
are calculate after "replace" is called. Please take a look at this commit
testReplace1
and testReplace2
are failing with incorrect value of rows()
property after an edit is performed.
@VladimirMakaev Thanks for reporting the bug. Fixed in version 0.5.5.
HI, I've trying to use your library in a project related to LSP and one issue I came across is calculating the length of a string between 2 positions. I'm doing something like this
Would it be possible to add an API under
TextEdit
something like: