Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String insertCodeBlock(String newBlock) {
- String text = textArea.getText();
- int start = 0;
- int count = 0;
- String buildNewTextArea = "";
- while (start >= 0) {
- int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.length());
- if (nextLineStart == -1) {
- nextLineStart = text.length();
- }
- String[] temp = diffBlocks.get(indexOfLine).split(",");
- int startLine = Integer.valueOf(temp[0]);
- int endLine = (Integer.valueOf(temp[1]) - 1) + startLine;
- if (count == startLine) {
- buildNewTextArea += newBlock;
- } else if (count < startLine || count > (startLine + (endLine - startLine))) {
- buildNewTextArea += text.substring(start, nextLineStart);
- }
- count++;
- start = text.indexOf(NEW_LINE, nextLineStart);
- }
- return buildNewTextArea;
- }
- private int getLineIndex(int line) {
- String text = textArea.getText();
- int start = 0;
- int count = 0;
- String buildNewTextArea = "";
- int index = 0;
- while (start >= 0) {
- int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.length());
- if (nextLineStart == -1) {
- nextLineStart = text.length();
- }
- if (count == line) {
- return index;
- }
- buildNewTextArea = text.substring(start, nextLineStart);
- index += buildNewTextArea.length();
- count++;
- start = text.indexOf(NEW_LINE, nextLineStart);
- }
- return text.length();
- }
- public String getLineContent(int startLine, int endLine) {
- String text = textArea.getText();
- int start = 0;
- int count = 0;
- String buildNewTextArea = "";
- while (start >= 0) {
- int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.length());
- if (nextLineStart == -1) {
- nextLineStart = text.length();
- }
- if (count >= startLine && count <= endLine) {
- buildNewTextArea += text.substring(start, nextLineStart);
- }
- count++;
- start = text.indexOf(NEW_LINE, nextLineStart);
- }
- return buildNewTextArea;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement